information
|visitors online
This function tells you how many visitors clicked how many times in a given timeframe.
See for example the clicks by visitors on the bottom of this page.
Just change the first variable in the counter_count function to point to a writeable file and include this file in your pages.
full source of visitors online [ line 1 - 34 ] | download visitors online
| 1 | <?php |
| 2 | function counter_write($filename, $filecontent, $mode='w') |
| 3 | { |
| 4 | if($fp = @fopen($filename,$mode)) |
| 5 | { |
| 6 | fwrite($fp, stripslashes($filecontent)); |
| 7 | fclose($fp); |
| 8 | return true; |
| 9 | }else{ |
| 10 | return false; |
| 11 | } |
| 12 | } |
| 13 | function counter_count($filename, $ip, $timeframe=1800) |
| 14 | { |
| 15 | $counterstr = time().'|'.$ip.'|'."n"; |
| 16 | $counter = array($ip=>1); |
| 17 | $hits = 1; |
| 18 | $counterdata = file($filename); |
| 19 | $number = count($counterdata); |
| 20 | for($i = 0; $i < $number; $i++) |
| 21 | { |
| 22 | $userdata = explode('|',$counterdata[$i]); |
| 23 | if($userdata[0] > time()-$timeframe) |
| 24 | { |
| 25 | $counter[$userdata[1]]++; |
| 26 | $hits++; |
| 27 | $counterstr .= $counterdata[$i]; |
| 28 | } |
| 29 | } |
| 30 | counter_write($filename, $counterstr); |
| 31 | return $hits.' hit'.($hits > 1 ? 's' : '').' by '.count($counter).' user'.(count($counter) > 1 ? 's' : '').' in the last '.($timeframe/60).' minutes.'; |
| 32 | } |
| 33 | echo counter_count('counter.txt', $_SERVER['REMOTE_ADDR']); |
| 34 | ?> |
37 hits by 19 users in the last 30 minutes.