FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Counter





misterdimiz
Does anyone can help me for a PHP counter script?
I'd like to have a counter that doesn't count each page refresh.
Possibly without database, but if it is necessary it's ok.

Thanks.
foggy
I'm not actually going to write out complete code for you, because if you wanted something precoded you can look on a script database such as http://hotscripts.com

I think it's always better to code it yourself because, for one thing, you get only the script that you need, expecially tailored for your needs, nothing more or nothing less.

When you start the process you have to decide how the script will work. The counting part is easy enough. Every time we want to increase the number (i.e. someone accesses the page) we read the number from wherever it is and add one to it and write it back. This is easlily done with a flat file (not a database)

You also state that you don't want it to increase with page refreshes. This means that you basically want it to could unique visits. There are 2 common ways to do this. Cookies, or recording the IP address of the person. I reccomend the first one for a no database code because storing hundreds or even thousands of IP addresses in a text file can slow down the script when it has to search for it line by line. If you wanted to go that route you would basically need to use a database.

Back to cookies, though. The disadvantage of them are that if the person has cookies disabled (which is becoming more and more common) the script won't function as intended. How they will be used with the script is when a person visits the site, they will be checked to see if they have a cookie set by your site that tells if they have been there. If they do, no number will be added, but if they don't a number will be added and a cookie will be set so the next time they visit they wont be counted. You can even set to cookies to expire after a certain amount of time so they will be counted again at some time in the future.

I wll leave the further research to you. If you don't know how to do it already, these are the things you will need to learn how to do in PHP:
+Look for a cookie
+Write a number to a text file
+read a number from a text file
+add 1 to that number
+set a cookie

If you get stuck don't be afraid to post your problem, we're here to help.
misterdimiz
Thanks a lot. I've found a script that allow me to set a time expiration before re-count the same visitor. I think it's good.
I've found the link in hostscript http://www.planetluc.com/en/scripts_flounter.php
Related topics
php counter
PHP Counter?
php Counter
Is there a site can report my site ?
I need PHP hits code
I want to make a counter in PHP.
Php users counter script
free php web counter,n@log
Tutorial: PHP Installed Modules Dynamic Reference Tool
Phoenix free PHP scripts
Form Hit Counter
Counter Strike Source Clan Website
PHP Help please
Website Counter
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.