![]() |
Hit Counter Help
Hello
I have recently decided I was going to create a Hit Counter in PHP for my site when it goes up. Sadly when I run it it decided that it will not work for me. The main file with all of the PHP coe in is called class.php. The contents of the file are: PHP Code:
I have a live example http://seaglass-jewellery.com/example/HitCounter/ (here) Can anyone help me? |
Well, your code isn't really great.
Your showHitCounter function prints a div but nothing in the div. The function never counts the amount of lines in the file and never prints this, so that you see nothing is normal. Your hit function has the variable $T which is never used and you check a hit with a cookie, which will never be the nice way for a hitcounter. Why is a cookie bad ? Because a user can simply unset the cookie and visit again. There are loads of hitcounters on the web that you can use, if your really want to code one yourself, then I suggest you first choose what you want to count. Every page view ? Every unique page view ? A user can view a page once per day ? If you simply want every page view, then you can simply save the number of hits and add 1 to it every view. For every unique page view, you will have to save the IP off a viewer and you can select all lines from a file to count the amount of unique views. And if you want a user to view a page once every x hours or days, you will have to save the IP with the Date of the view and check if the date is before the x hours or days. |
according to php tutorials you can create a counter text file of the name hitcounter.txt and save it to the same directory you will put your hit counter in.
Open your php editor. Save the document as counter.php. Set your opening statement for PHP script. PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
To use this script you just have to add a php statement that calls that php file. Use the following include: PHP Code:
|
| All times are GMT. The time now is 09:28 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0