|
|
|
|
![]() ![]() |
Jul 4 2006, 08:49 PM
Post
#1
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 164 Joined: 2-July 06 From: England Member No.: 25,974 |
First create a dir "counters" in root add to it dailyhits.txt, hits.txt, online.txt an CHMOD 0777, place this on index:
CODE //online counter $tim = 120+time(); $time = time(); $f = "counters/online.txt"; $nusk = file($f); $sk = count($nusk); $in = $HTTP_USER_AGENT.$REMOTE_ADDR; $fp = fopen($f, "w+"); for($i=0; $i<$sk; $i++) { list($nix, $timf) = explode("|", $nusk[$i]); if($nix !== $in && $timf>$time) { fwrite($fp,$nusk[$i]); }} fwrite($fp, "$in|$tim|\n"); fclose($fp); $xfile=file('counters/online.txt'); $onlinecount=count($xfile); echo "-Online: $onlinecount<br/>"; //day hits counter $fn = "counters/dayhits.txt"; $fp = fopen($fn, "a+"); $fs = filesize($fn); $tdy = date("d/m/y"); if ($fs==0) { $co = 1; fwrite($fp, $tdy."-".$co); }else{ $info = fread($fp, $fs); $cdata = explode("-", $info); ftruncate($fp, 0); if($tdy==$cdata[0]) { $co = $cdata[1]+1; fwrite($fp, $tdy."-".$co); }else{ $co = 1; fwrite($fp, $tdy."-".$co); } } fclose($fp); echo "-Daily hits: $co<br/>"; //total hits counter $fp=fopen("counters/hits.txt","a+"); fputs($fp,"1"); fclose($fp); $totalhits=filesize("counters/hits.txt"); echo "-Total hits: $totalhits</small></p><p align=\"center\"><small>"; |
|
|
|
Jul 5 2006, 12:32 AM
Post
#2
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 57 Joined: 22-June 06 Member No.: 25,524 |
Once I get my hosting here I'll be sure to try this out. Thanks for the code.
|
|
|
|
Jul 5 2006, 09:32 AM
Post
#3
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 20 Joined: 7-June 06 Member No.: 24,827 |
hye buddy , thanx for your soo nice sharing . i eas desperately searching for such type of code i am going to use in on my website. thanx again for your so nice sharing.
greets. |
|
|
|
Jul 5 2006, 05:10 PM
Post
#4
|
|
|
Newbie ![]() Group: Members Posts: 9 Joined: 5-July 06 Member No.: 26,116 |
oh how nice, i wrote that code
|
|
|
|
Jul 8 2006, 02:38 AM
Post
#5
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 164 Joined: 2-July 06 From: England Member No.: 25,974 |
Dj will you stop follow me around wap/web with your sly comments! You uploaded ONLY THE DAILY HITS to my old site to share ok, so i also did SHARE IT! An i doubt you wrote is as you code like a monkey (with no hands or keyboard pmpl) ;-)
--- ok i have an update for the counters, i left the online out as it confuses me pmpl, but this new one runs off only one text file (so create file wappyCOUNT.txt) and CHMOD 0777, it will display for you... +daily hits +hits yesterday +days open +months open +years open +total hits +average daily hits CODE //(c)wappyCOUNT $fn = "wappyCOUNT.txt"; $fp = fopen($fn, "a+"); $fs = filesize($fn); $tdy = date("d/m/y"); if ($fs==0) { $co = 1; $yesterday = 0; $open = 0; $total = 1; fwrite($fp, $tdy."-".$co."-".$yesterday."-".$open."-".$total); }else{ $info = fread($fp, $fs); $cdata = explode("-", $info); ftruncate($fp, 0); if($tdy==$cdata[0]) { $co = $cdata[1]+1; $yesterday = $cdata[2]; $open = $cdata[3]; $total = $cdata[4]+1; fwrite($fp, $tdy."-".$co."-".$yesterday."-".$open."-".$total); }else{ $yesterday = $co; $open = $cdata[3]+1; $co = 1; fwrite($fp, $tdy."-".$co."-".$yesterday."-".$open."-".$total); } } fclose($fp); echo "-Daily hits: $co<br/>"; echo "-Yesterday: $yesterday<br/>"; echo "-Days open: $open<br/>"; //months open $months = $open/29.6666667; $months = round ($months, 1); echo "-Months open: $months<br/>"; //years open pmpl $years = $open/356; $years = round ($years, 2); echo "-Years open: $years<br/>"; //total hits echo "-Total hits: $total<br/>"; //average daily hits $average = $total/$open; $average = round ($average); echo "-Average daily: $average<br/>"; if is any errors with this please forgive me im a little drunk pmpl |
|
|
|
Jul 8 2006, 03:43 AM
Post
#6
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 30 Joined: 8-July 06 Member No.: 26,279 |
Yeah I found a error, wait nvm that was just my browser screwing up.
|
|
|
|
Jul 11 2006, 01:22 AM
Post
#7
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 164 Joined: 2-July 06 From: England Member No.: 25,974 |
No you are correct there were two errors. Here is a corrected update. I will work on it more later :-)
--- Oops i made errors again so i have definatly fixed this time and here is the code im using on my own site. You must in your root create a folder called "counters" and inside this counters folder put files online.txt, wappyCOUNT.txt, and counter.dat. You must set permissions on ALL the files in the counters folder to chmod 0777 ok. Then on your index page copy and paste this code where you would like the counters displayed. CODE //online counter $tim = 120+time(); $time = time(); $f = "counters/online.txt"; $nusk = file($f); $sk = count($nusk); $in = $HTTP_USER_AGENT.$REMOTE_ADDR; $fp = fopen($f, "w+"); for($i=0; $i<$sk; $i++) { list($nix, $timf) = explode("|", $nusk[$i]); if($nix !== $in && $timf>$time) { fwrite($fp,$nusk[$i]); }} fwrite($fp, "$in|$tim|\n"); fclose($fp); $xfile=file('counters/online.txt'); $onlinecount=count($xfile); echo "-Online: $onlinecount+<br/>"; //(c)wappyCOUNT $fn = "counters/wappyCOUNT.txt"; $fp = fopen($fn, "a+"); $fs = filesize($fn); $tdy = date("d/m/y"); if ($fs==0) { $co = 1; $open = 0; fwrite($fp, $tdy."-".$co."-".$open); }else{ $info = fread($fp, $fs); $cdata = explode("-", $info); ftruncate($fp, 0); if($tdy==$cdata[0]) { $co = $cdata[1]+1; $open = $cdata[2]; fwrite($fp, $tdy."-".$co."-".$open); }else{ $co = 1; $open = $cdata[2]+1; fwrite($fp, $tdy."-".$co."-".$open); } } fclose($fp); echo "-Daily hits: $co<br/>"; echo "-Days open: $open<br/>"; //total hits $counter_array = file("counters/counter.dat"); $total = $counter_array[0]+1; $fp = fopen("counters/counter.dat","wb"); fputs($fp,$total); fclose($fp); echo "-Total hits: $total<br/>"; //average daily hits $average = $total/$open; $average = round ($average); echo "-Daily average: $average<br/>"; //average hourly hits $averagehour = $average/24; $averagehour = round ($averagehour); echo "-Hourly average: $averagehour<br/>"; //average week hits $averageweek = $average*7; $averageweek = round ($averageweek); echo "-Weekly est: $averageweek+<br/>"; //est month hits $averagemonth = $average*29.5; $averagemonth = round ($averagemonth); echo "-Monthly est: $averagemonth+<br/>"; //average year hits $estyear = $average*356; $estyear = round ($estyear); echo "-Yearly est: $estyear+<br/>"; i apologise again for the errors on my previous counter snippets but i did use and get the errors on my own site also. Well its fixed for sure now, if anyone can update this further please do so and post your code here :-) This post has been edited by wappy: Jul 12 2006, 02:22 PM |
|
|
|
Jul 28 2006, 04:55 PM
Post
#8
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 183 Joined: 24-July 06 From: Cape Town Member No.: 27,194 |
I don't know if this helps but you may want to change 356 days to 365 days, there are 365 days in a year right? And you may want to change the avereage for the month from 29.blah to 31.42. I hope this helps and maybe it will give slightly more accurate readings.
|
|
|
|