|
PHP -> Basics -> Simple PHP Hit Counter Script
Simple PHP Hit Counter Script
- Apr 15 2006
This tutorial will show you how to create a very simple hit counter in PHP.
Tutorial Monkey is a database of technology-related tutorials. We write our own tutorials as well as linking to other ones in the web. If you would like to submit a link to your tutorial, feel free to do so. Just click on "submit" at the top of the page. Note: Images may result in loss of quality due to the fact that we must resize them to fit the design. You can click resized images to see its original image in a new window. Sponsors Important It is worth noting that this tutorial is paginated, and that the entire tutorial contains 4 pages. Just remember that the tutorial is not finished just after the first page! PHP 4+ is required for this tutorial. PHP 5 is optional This tutorial is for beginners with very limited knowledge of PHP. You will learn to make a very simple hit counter. The counter isn't important -- it's the techniques used that you should try to remember. Something similar will pop up later on, so try to remember what was said in this tutorial. If you are rather experienced with PHP, you still can follow along. It never hurts to brush up on some old easy stuff. I will show you how to create a hit counter (not uniques, just simple hits) using a flatfile. Alright, let's get started. Step 1 A
Open your text editor and create a new document. I will use NotePad as an example here. Before you even start typing a single thing, press File -> Save As... and save your document first. We want to create all our files first before starting the code. I saved my file as "counter.php". The name doesn't matter, but make sure you don't forget the .php extension.
Step 1 B
Now, we need to create a new file to store the number of hits. This is called a flat file. A flat file is similar to a database, but it is a file instead. Press File -> New. This new file will consist of nothing but a number. This number will be the hit count. Because we've just started, type "0" in the document and press File->Save As.... Save this file as a TXT document. I named mine "hits.txt", but you can name it differently.
This tutorial is paginated, please navigate [ Steps 1-2 ] [ Steps 3-4 ] [ Steps 5-6 ] [ Steps 7-8 ] « Back |