Jump to content
xisto Community
Sign in to follow this  
wappy

Simple Text Counters Counters i use on wap sites ;-)

Recommended Posts

First create a dir "counters" in root add to it dailyhits.txt, hits.txt, online.txt an CHMOD 0777, place this on index:

//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>";

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

//(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 hitsecho "-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

Share this post


Link to post
Share on other sites

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.

//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 :-)
Edited by wappy (see edit history)

Share this post


Link to post
Share on other sites

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. :)

Share this post


Link to post
Share on other sites

thanks to person above :-) and here is a nice new update
---
Here is another update of the counters code, it now has weekly, monthly, and yearly estimates based on the visits recieved on the current daily hits as well as the estimates based on the total average hits. (hope that makes sense lol)
just make sure you have created any files refered to in this code in a folder called counters, and paste this code on the index of your site. Please feel free to update it and post here your updates :-)

//////(c)wappyCOUNT//daily hits$fn = "counters/wappyCOUNT.txt";  $fp = fopen($fn, "a+"); $fs = filesize($fn); $tdy = date("d/m/y"); if ($fs==0) {  $dailyhits = 1;$open = 0;  fwrite($fp, $tdy."-".$dailyhits."-".$open); }else{  $info = fread($fp, $fs);  $cdata = explode("-", $info);  ftruncate($fp, 0);  if($tdy==$cdata[0])  {   $dailyhits = $cdata[1]+1;$open = $cdata[2];   fwrite($fp, $tdy."-".$dailyhits."-".$open);  }else{$dailyhits = 1;$open = $cdata[2]+1;     fwrite($fp, $tdy."-".$dailyhits."-".$open);  } } fclose($fp); echo "-Daily hits: $dailyhits<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);$averagehourtoday = $dailyhits/24;$averagehourtoday = round ($averagehourtoday);echo "-Hourly average: $averagehour|$averagehourtoday<br/>";//est week hits$estweek = $average*7;$estweek = round ($estweek);$estweektoday = $dailyhits*7;$estweektoday = round ($estweektoday);echo "-Weekly est: $estweek|$estweektoday<br/>";//est month hits$estmonth = $average*31.4;$estmonth = round ($estmonth);$estmonthtoday = $dailyhits*31.42;$estmonthtoday = round ($estmonthtoday);echo "-Monthly est: $estmonth|$estmonthtoday<br/>";//est year hits$estyear = $average*365;$estyear = round ($estyear);$estyeartoday = $dailyhits*365;$estyeartoday = round ($estyeartoday);echo "-Yearly est: $estyear|$estyeartoday<br/>";

Share this post


Link to post
Share on other sites

thanks to person above :-) and here is a nice new update---
Here is another update of the counters code, it now has weekly, monthly, and yearly estimates based on the visits recieved on the current daily hits as well as the estimates based on the total average hits. (hope that makes sense lol)
just make sure you have created any files refered to in this code in a folder called counters, and paste this code on the index of your site. Please feel free to update it and post here your updates :-)

//////(c)wappyCOUNT//daily hits$fn = "counters/wappyCOUNT.txt";  $fp = fopen($fn, "a+"); $fs = filesize($fn); $tdy = date("d/m/y"); if ($fs==0) {  $dailyhits = 1;$open = 0;  fwrite($fp, $tdy."-".$dailyhits."-".$open); }else{  $info = fread($fp, $fs);  $cdata = explode("-", $info);  ftruncate($fp, 0);  if($tdy==$cdata[0])  {   $dailyhits = $cdata[1]+1;$open = $cdata[2];   fwrite($fp, $tdy."-".$dailyhits."-".$open);  }else{$dailyhits = 1;$open = $cdata[2]+1;     fwrite($fp, $tdy."-".$dailyhits."-".$open);  } } fclose($fp); echo "-Daily hits: $dailyhits<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);$averagehourtoday = $dailyhits/24;$averagehourtoday = round ($averagehourtoday);echo "-Hourly average: $averagehour|$averagehourtoday<br/>";//est week hits$estweek = $average*7;$estweek = round ($estweek);$estweektoday = $dailyhits*7;$estweektoday = round ($estweektoday);echo "-Weekly est: $estweek|$estweektoday<br/>";//est month hits$estmonth = $average*31.4;$estmonth = round ($estmonth);$estmonthtoday = $dailyhits*31.42;$estmonthtoday = round ($estmonthtoday);echo "-Monthly est: $estmonth|$estmonthtoday<br/>";//est year hits$estyear = $average*365;$estyear = round ($estyear);$estyeartoday = $dailyhits*365;$estyeartoday = round ($estyeartoday);echo "-Yearly est: $estyear|$estyeartoday<br/>";
you confussing me bro,but thanx anyway

Share this post


Link to post
Share on other sites

i confuse my self some times lol :-)but you can see it working on my index chatz :-)

Share this post


Link to post
Share on other sites

Wappy I guess you don't want to share the script timer? If You want to share it please post it here thenks. because thats about the only thing missing from your counters :)

Share this post


Link to post
Share on other sites

no i don't mind sharing it but mine needs updating. Before you post a topic or ask for code/scripts search the forum. I found the script timer come right here in this php programming forum at http://forums.xisto.com/ :)

Share this post


Link to post
Share on other sites

Iam using a very simple and more optimised hit counter on my site. For implementing that, the procedures are:-

 

Make a file named hits.txt

 

 

Change its mode to 0777

 

 

Create a php file naming hits.php

 

 

Put the following code on the hits.php file

 

<?php
    $hits = file_get_contents("hits.txt");
    $hits = $hits+1;
    $fp = fopen("hits.txt","w");
    fwrite($fp,$hits);
    fclose($fp);
    echo $hits;
?>

 

 

Then put the code given below to the page where you like to display the hits on the page:

 

 

<script language="PHP">
include("hits.php");
</script>

 

This script works only on php files (pages). If your pages are .htm or .html extension, just replace its extension with .php without doing any other things. This script will work on your pages. There also an advanced technique to parse php through html files. But on here this is well suited. Enjoy the simple script and implement on your site.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.