|
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 Step 2
Alright, now that we've got our files set up, lets start codin'. Open up counter.php (or whatever you named it) and type the PHP tags.
<?php
Step 3
Now, we open up the flat file (hits.txt) and tell PHP to read the number inside and set it as a variable (we've already put "0" into hits.txt)
<?php
The function file_get_contents reads all the text in the file that is quoted in the first argument (the first argument being hits.txt in this case) and puts it into a string. A string is simply data. It could be text, numbers, anything. In this case, it is only one thing -- a number. When we put "$hits =", this means we are defining a variable. In this case, we are saying that the variable $hits (all variables must have a dollar sign before it) is equal to everything inside hits.txt (which in this case, is only "0"). This tutorial is paginated, please navigate [ Steps 1-2 ] [ Steps 3-4 ] [ Steps 5-6 ] [ Steps 7-8 ] « Back |