Hello, how do you know the number of guests who view the site, namely guests, and not registered users?
|
2 answers
Usually they make sessions in the database and look at these sessions.
ala:
sessionId | userId | ....
select count(*) as cnt from sessions where userId=0; |
$fp = fopen("log.txt","r"); $x = fread($fp,filesize($fp)); fclose($fp); if (isset($_COOKIE['1']) == false) { $fp = fopen("log.txt","w"); $x++; fwrite($fp,$x); fclose($fp); } setcookie(1,1,time()+31536000); echo $x." посетителей"; The easiest. It reads from the file, how many have already gone, if there is nothing in the cookies, then it increases the number, sends the cookie always and for a long time, if the user doesn’t turn on the cookie, it’s bad, but you’re in touch right now, so ip, but then it is already better to store in databases, and it is better to put some thread counter LiveInternet))
|