Back to Top
The nuts and bolts for
Creative web development

PHP Custom Web Statistics – Part 2

In the second part of this tutorial about creating your own custom web statistics, we analyse the data that is collected each time a page is viewed. We'll be looking at various ways of reading the data we require from the database, and making MySQL work harder by using some of its extra functions to process our data.

We create a function to execute an SQL query, so that we don't repeatedly enter code to open and close the database etc, which makes for shorter code that’s easier to understand and debug. We then create a range of functions that could extract certain statistics from the data stored in the database. We create a set of functions which create the SQL queries dynamically, and can be easily inserted into the framework of the main site pages.

We then construct a page which serves as the index page for the web statistics application, and shows an overall view of every year that has data in the database, showing each year and the number of hits per month.

Finally, we create a page that displays a single year's-worth of data at a time, in a table which is dynamically generated using PHP, and shows more detailed figures for the year.

 

Please note that this article forms part of a chapter in the DMXzone e-book PHP Web Applications for Dreamweaver: Juicy Solutions for the Busy Developer.

 

Author: Gareth Downes-Powell Price: $3.39 Rating:

Graphing: dynamic 3D bar charts

In today's article on dynamic graphing with PHP, we convert the supplied script that plots a a line graph into one that plots a bar chart on the fly from dynamic data:



Then, we discover how to fill the bars with colour:


Finally, we give the bars a 3D perspective effect:


The start-up code is provided, so the tutorial is for Dreamweaver users with any level of PHP experience.

Author: Allan Kent Price: $3.39 Rating:

Graphing with PHP: Line Graphs

In our tutorial last week, Graphing with PHP, we started building a class that you could use to draw a graph using the PHP Image functions.

We used a simple data holding object that contained all of the data that we needed to draw our graph, and then passed that to a graph drawing script by storing the data temporarily in a Session variable on the server. This method allowed us to use our PHP image drawing scripts as the SRC of an IMG tag so that the dynamic graphics could be embedded within an HTML page.
 
At the moment, our class just plots asterisks, so the first thing that we will need to do is change our graph from drawing in asterisk characters for the plot points, to using an actual line. It's helpful to have read the last tutorial, but all the code is supplied for download to allow you to product dynamically-generated line graphs on the fly from PHP.
Author: Allan Kent Price: $3.39 Rating:

PHP Custom Web Statistics

Keeping logs of who visits your site is useful as it allows you to see how many people are visiting your site, and which pages are the most popular and most frequently visited. Pages which have low visitor numbers can then be changed to make them more appealing. Alternatively, it may turn out that your navigation system isn't working as well as it could be, and you can then change it to make the pages with low numbers of visitors easier to find.

Creating your own system using PHP and MySQL means that you can still have detailed statistics about who visits your site, even if your web host doesn't allow access to the server log files. It also means that you can create your own custom reports to show the data that is of most interest to you, rather than being locked into the standard reports that many web hosts provide.

  • In this first tutorial of the series, we first look at how to obtain information about visitors to your web site such as the users ip address and information about the users browser and operating system from the special PHP $_SERVER array.
  • We then create an include file containing the MySQL database connection parameters which can be added to any page that requires access to a MySQL database. This gives us the advantage that if the MySQL server is changed in the future, then the new connection parameters only need to be changed once in the include file rather than on every page that uses the MySQL database.
  • Then we create another include file that can be easily added to any web page that you want to log, and writes details about the web page visitor to a MySQL database table ready to be analysedata later date.

 

Please note that this article forms part of a chapter in the DMXzone e-book PHP Web Applications for Dreamweaver: Juicy Solutions for the Busy Developer.

 

Author: Gareth Downes-Powell Price: $3.39 Rating:

Graphing with PHP

In this and next weeks’ tutorials we will be building on what we have covered by developing a set of basic objects that you can use for drawing graphs from dynamic data. After all, what use is having these great tools for drawing graphs and charts if you can't draw them dynamically? If that were the case you may as well stick to using Macromedia Fireworks or exporting a graph from Microsoft Excel.
 
We'll build up a PHP script that implements a graph object. We’ll start simple and explain the whys and wherefores as we go along – don’t worry of you missed the previous two articles as we'll do some quick revision as we go along.

Today we:
  1. create  a script that implements a class to store all of our graph data. 
  2. We will instantiate the object in our main script and give it all the information about our graph. 
  3. Once we have all of the data in place we will then write out our image tag. 
  4. As that happens we will save the entire object into a session variable and pass an identifier to that session variable to the graph drawing script.
  5. The graph drawing script will then access the graph data object through the session variable and draw the graph accordingly.

This tutorial contains some maths, but the code is provided and is suitable for intermediate PHP developers using either Dreamweaver MX or MX 2004.

Author: Allan Kent Price: $3.39 Rating:

PHP: Dynamic Arcs, Circles and Polygons

Not all graphics on web pages are for design only. A lot of sites used in business or financial reporting need to show dynamic information graphically, and because that information updates constantly, the graphs need to be drawn on the fly. In this weeks tutorial we will continue on with some more complex shapes – curves, ellipses and polygons. We’ll also take a look at some of the maths involved with drawing polygons. As the series progresses, this will lead up to a routine that will plot graphs on the fly from dynamic data.

This tutorial contains some maths, but the code is provided and is suitable for intermediate PHP developers using either Dreamweaver MX or MX 2004.

Author: Allan Kent Price: $3.39 Rating: Not enough votes

PHP Shape drawing tools

In a number of tutorials towards the end of last year we took a look at working with images in PHP.  The functionality and techniques that we looked at all worked with existing images that you had already taken with a digital camera, scanned in, or created yourself.  We saw how to make thumbnails, save these thumbnails in different formats and how to play with the colours within these images.  And this is all great if you have existing images to work with, but what happens if you want to draw simple shapes dynamically within your image?  The image functions within PHP can also do this and there are a number of functions, some of which you have already seen, that allow us to do this.
 
When most people think of creating images for web sites, they think of a program like Adobe Photoshop or Macromedia Fireworks and think of all the creative things they can do to make the page look good.  With enough time and effort you could get similar results using the PHP image functions, but this is not why we use them – these functions are aimed at more practical uses for images – creating simple navigation buttons on the fly, drawing maps or diagrams from raw data, annotating existing images or drawing graphs from dynamic data.
 
In today’s tutorial we will take a look at some of the basics for drawing shapes on an image; this tutorial can be used by itself, or as part of a series over the coming weeks which will demonstrate how to build  diagrams and charts on-the-fly from dynamic data.
Author: Allan Kent Price: $3.39 Rating:

PHP: Working with Image colour

Using the free GDLib extensions to PHP, we can dynamically make thumbnails, save images to disc and manipulate them in other ways. in this tutorial, Allan shows how to manipulate the colours within an image, either to tint them or greyscale them (we've seen this technique used in an application that allows you to upload images into an on-line "newspaper" complete with black and white photographs!).

This tutorial assumes no prior knowledge of PHP.
Author: Allan Kent Price: $3.39 Rating: Not enough votes

PHP User comments system

In this tutorial, we’re going to build a system to allow users to add comments to the bottom of your web pages, which is becoming more and more popular lately for a variety of different applications. For example, blogs are now starting to allow users to add comments so readers can join in the discussion, and tutorials have comments sections where users can add their own notes, or comment about the brilliance of your writing for example. The system could also be used to create a guest book application for a site; in fact the principles can be used for pretty much any system which allows users to add data.

We first build a page that allows the user to add comments, which are then stored in a table in a MySQL database. We place the MySQL connection parameters in an include file, so they can easily be added to any page which uses the database, without having to retype them each time, and so they are easily changeable in future if you change servers for example.
 
We then create a PHP include file which can be added to an existing page to show the relevant comments from the database for that particular page. 
Author: Gareth Downes-Powell Price: $3.39 Rating:

Saving PHP thumbnail data

In today’s tutorial we write a series of PHP scripts that allow a page to take a user-uploaded image, resize it - and generate a thumbnail of the image that is uploaded.  We’ll then take that thumbnail data and save it in a database.  When we look at how we can save our images in a database, we’ll have to look at how we can first change the binary data so that it is safe to store in the database, as well as taking a look at how PHP can ‘buffer’ its output. This tutorial utilises the free GD library.
Author: Allan Kent Price: $3.39 Rating:

Thumbnail generation with PHP

In this tutorial we will be taking a look at how we can open existing images, check on their current dimensions and then intelligently do a proportionate resize on them., dynamically creating thumbnails on the fly to display in the browser.

In previous tutorials we have looked at how we can set up PHP so that our extensions are correctly installed. Rather than covering that again, this week we will look at ways that you can check if the extension that you want is installed and supports the things that you want to do. We will be working with the free GD extension.

Author: Allan Kent Price: $3.39 Rating: Not enough votes

Creating Calendars in PHP – Part 4

In this last part of the series on creating a calendar application in PHP, we create an include file to hold the parameters required to connect to the MySQL database. Next, we create a page that displays all calendar events on a particular day, using the date which is passed as a URL parameter to find the correct records from the database.

Then, we create a page which allows a user to easily add events to the database through a simple web interface. Finally, we create a multi purpose page that allows a user to edit existing records in the database, or delete a calendar event from the database.

All the code is provided for download, so if you haven't followed the previous tutorials, it's all available for you to build this sophisticated calendar application for your users.

Please note that this article forms part of a chapter in the DMXzone e-book PHP Web Applications for Dreamweaver: Juicy Solutions for the Busy Developer.

 

Author: Gareth Downes-Powell Price: $3.39 Rating: