header

MySQL/PHP (w/GD) counter



I’ve finished for the most part (as far as I know) The RayDehler Counter . V1.0 is completed, and I can think of many improvements already that need to be done, but this is a good start.

  • Here’s how it works

    Redirected using apache’s mod_rewrite, it takes the url <img src=”http://raydehler.com/counter/2.png”> and transforms it to <img src=”http://raydehler.com/counter/counter.php?id=2″>.

    Then, using the GD libraries of PHP4, it connects to the MySQL database, grabs the row corresponding to the ID. It then increments the ‘loads’ and puts the new value back into the database. It then creates the image with its size based on the value of the number of the ‘loads’ field. Lastly, it outputs the ‘loads’ value to the image and destroys the image.

  • Here it is in action
    This page has blargpost has been viewed Blarg Counter times.
    (Note the img uri is just http://raydehler.com/counter/2.png)

    Ironically the thing about it that I’m most proud of is the user management using PHP sessions for authentication. Now that this is done, I can potentially create many more scripts and use the current as a backbone for each of them.



  • Leave a Comment

    blogtimes