I'm looking for some simple script in PHP only to count unique visitors. I just need to include code and know the number of unique visits(updated online). Do You know something good ?
Well first of all you are going to need a system that logs the visits to a database so your script can analyse it later.
" Creating a cookie based on timestamp and IP adress will help you out to do this " Exacly, something like this is perfect but there is no ready script like this ?
I have already created something similar for my own site. Basically you are going to need a PHP file that is included in every one of your files that you want logged. Here is my own [modified] script I use (I know it's messy): <?php //this will insert the user's details into the database. $ip_user_log_mod = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); $host_user_log_mod = mysql_real_escape_string($_SERVER['SERVER_NAME']); $page_user_log_mod = mysql_real_escape_string($_SERVER['REQUEST_URI']); $time_user_log_mod = mysql_real_escape_string(time()); $rdns_user_log_mod = mysql_real_escape_string(gethostbyaddr($ip_user_log_mod)); $uagent_user_log_mod = mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']); $referrer_user_log_mod = mysql_real_escape_string($_SERVER['HTTP_REFERER']); $xforwardedfor_user_log_mod = mysql_real_escape_string(getenv(HTTP_X_FORWARDED_FOR)); $via_user_log_mod = mysql_real_escape_string(getenv(HTTP_VIA)); $sql = ("INSERT INTO `Log` ( `IPAddress` , `PageRequested` , `Seconds` , `ReverseDNS` , `UserAgent` , `Referrer` , `RealIPAddress` , `Via` , `read` ) VALUES ('" . $ip_user_log_mod . "', 'http://" . $host_user_log_mod . $page_user_log_mod . "', '" . $time_user_log_mod . "', '" . $rdns_user_log_mod . "', '" . $uagent_user_log_mod . "', '" . $referrer_user_log_mod . "', '" . $xforwardedfor_user_log_mod . "', '" . $via_user_log_mod . "' , '0')"); $sql = preg_replace( '/\\\\/u', '\\\\\\\\', $sql); $sql = preg_replace( '/([%_])/u', '\\\\$1', $sql); mysql_query($sql); ?> Code (markup): Basically you will need to setup a MySQL database and a table called Log, put in your own username and password for the script (it won't work without the username and password) and learn some PHP so you can analyse the results. onehundredandtwo.
Sorry I don't have the perfect script with me but the script written above seems to be ok. I think it will work out because logically its perfect.
Often when people ask questions like this they're looking for some kind of analytics on their site - you may want to check out google analytics. It's pretty easy to set up and it will give you a lot better data than just number of unique visitors. Or use both, can't hurt