Jul 25, 2008

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

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming
Pages: 1, 2

free web hosting

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

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

 

 

 


Reply

siotoxin
Once I get my hosting here I'll be sure to try this out. Thanks for the code.

Reply

innocent-devil
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.

Reply

dj.dance
oh how nice, i wrote that code biggrin.gif

Reply

wappy
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

 

 

 


Reply

nehmanator333
Yeah I found a error, wait nvm that was just my browser screwing up.

Reply

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

Reply

juice
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. dry.gif

Reply

wappy
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 :-)
CODE

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

Reply

Chatz
QUOTE(wappy @ Jul 29 2006, 10:56 PM) *

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

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

Reply

Latest Entries

wappy
the SCRIPT TAG does on work on WML/PHP wap scripts only HTML (just incase anyone didn't know this) :-)

Reply

ivenms
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

HTML
<?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:


HTML
<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.

Reply

Goth_Punk
Hahahahaha the drunkerd wapmaster laugh.gif nice wappy

Reply

wappy
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 www.trap17.com tongue.gif

Reply

juice
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 huh.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Similar Topics

Keywords : text counters counters wap sites

  1. Php Calculator That Calculates Genetic Percentages? - I need help finding sites or tutorials. (2)
  2. Best Sites For Learning Php-mysql - (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!...
  3. Dynamic Image / Signature Generator - a simple code to change text on an image (12)
    In search of dynamically changing quote, saying or all other types of text on an image I came across
    a code that I have modified to fit my initial usage. This procedure requires two files and short
    knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
    procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
    at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
    CODE <?php header("Content-type: image/png"); �...
  4. I Just Wrote A Script For A Php Text Editor! - (8)
    Yes, I just wrote out a script for a PHP text editing program. It is very basic but I would like to
    be able to actually use this and update it. First, I need version 0.7 to be proofread. It will be
    upgraded to 0.8 after closed beta, 0.9 after open beta, 1.0 when ready. I would love to have some
    people help with this project. Right now it is a simple PHP script and HTML form. Here is the
    current script. I would like it to be proofread. $fileName = "$_REQUEST ";
    $fHandle = fopen($fileName , 'w') or die("Can't write file."); $fCont...
  5. Php Text Editor - (1)
    Is there any possible way using XML and PHP that you could create a text editor that can save files
    in your documents and also make a hotlink to your site. Much like a online notepad. I would like to
    know how I would make on of these and whether or not MySQL or XML would be a good language to use
    for storing data. My current idea deals with only PHP and iframes. It really isn't an editor
    though, more like a notes page. I would like a way though to be able to create a database with info
    stored from the PHP script which and be able to save to your hard drive. Also, i...
  6. [php]simple Flat File Text Manipulator - Example on how to use forms to write to files in PHP (3)
    I made a simple flat file text editor, that can show you probably how simple it is to use forms with
    php and write that data to file. This example has 2 files, submit.php, and postit.html. Submit.php
    is used to write title, and some text, and add html tags, and paragraph tags where new paragraphs
    are. Here's the file with comments. I think that HTML really doesn't need some more
    explaining. CODE Title: <br /> <input type="text"
    name="title" size="53"> <br /> Text: <br />
    <textarea nam...
  7. Forms, Text Files, And Php For A Signature Generator. - Help a little. (1)
    Hello everyone! I am in need of some code a for a signature generator I am making. I am using
    BuffaloHELP's code for the php file, now I am trying to improve that code by making a form in a
    html file that will have the user say what is on the sig! But now, I need help getting the form
    data that is posted by the user to get into that sig! There is a file, sig.txt, where that tells
    the php file what text will go on the sig. But how can I make the form data in the html file go into
    the text file so it will go onto the sig? You might want to read BuffaloHELP&...
  8. Help Php: How To Load String From Text File (solved) - Loading string from text file when you click on your link (9)
    I learned the way to load other files with the code posted on this forum. Now i wanted to try
    something for my side menu. I am calling this a string, --> $tekst , maybe it's
    called something else i'm not sure Now let's say i have a file called details.txt In that
    file i would like to have something like this $detailsaboutphp1 = ("details details details
    1"); $detailsaboutphp2 = ("details details details and even more details 2"); How to make a
    code that loads those $strings on click of a mouse. When we tried to load extern...
  9. String/text Formatting? - (4)
    right i was wondering if someone could help me with this: I notice on this site if i make a topic
    for example WAppY rOCks WaP, it will come out like Wappy Rocks Wap. I also want to do this to my
    forums, can anyone give me the code to format a string of text in this way? THANKS IN ADVANCE ...
  10. flatfile guestbook for wap sites - (3)
    I dont know if any of you guys have a wapsite but i do so i made a guestbook. Here ...
  11. Php Scripts Free For Every One - list of the best php scripts sites (12)
    so what's you favourites php scripts sites? mine are : 1- hotscript 2- phpbuilder 3-
    developershed 4- internet so what's yours? /biggrin.gif" style="vertical-align:middle"
    emoid=":D" border="0" alt="biggrin.gif" />...
  12. Coding Your Sites ? - Coding your sites (20)
    What kind of coding do you use on your sites? I have so far learnt using a little tables and
    div/css. /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> ...
  13. Papular Wap Scripts 4 Your Sites - collection of WAP scripts (3)
    Redirect script webbrowser from wap to web and wapbrowser from web to wap. CODE <?
    $htmlredirect = "http://kralj.frih.net"; $wmlredirect =
    "http://kralj.r8.org";
    if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0){
    header("Location: ".$wmlredirect);} else{ header("Location:
    ".$htmlredirect); exit;} ?>
    ================================================================== Graphic counter. !!!
    Dont forget to create count...
  14. Anyone Know Any Good Sites To Learn Php - (17)
    ive tried many sites like www.w3school.com. Ive tried some of the guides in the forums here. Ive
    triedwww.php.com. If u have any other sites please tell me and make it a site that is easy to learn
    php and to understand wat they are saying please. ANd maybe a site to learn mySQL but i am using
    w3school for mySQL...
  15. Problem With Firefox Text Alignment - (9)
    I just have a really simple annoyin prob with my site which I have only just noticed. If i view the
    site in IE the alignment is fine but when in Firefox it isnt properly aligned. The user searches the
    db and it returns a table with the results.. PHP Code: CODE echo '<br><table
    width="871" border="0" align="center" cellpadding="0"
    cellspacing="0"><tr><font face="Verdana, Arial, Helvetica,
    sans-serif" size="2"><strong>'; echo 'Artists beginning with
    '.$...
  16. Reading Site's Source Code With Php - is this possible? (8)
    Hey guys. I want to know if it's possible to read a site's source code using PHP. Would
    using $blah = file(http://google.com); work? I want to make a script that will retrieve the
    comic of the day from http://comics.com/ . Currently, I have another source, http://ucomics.com/ ,
    but that site doesn't have some of the ones that I want. The thing is, http://ucomics.com/
    uses an easy file name for each comic in their comic of the day. Here's an example of the file
    name: ga050826.gif. That is for August 26th, 2005. Simple stuff. http://comics.com/...
  17. Garbage Text - when i added php includes to a page (2)
    When i added php included to a page, it produced this really really weird garbage text befor and
    after the table i have on the page. I was wondering if this has ever happened to anyone else. Not
    sure what's producing the gargabe, i mean it's only a couple of characters, and i've
    gone through everything and can't find anything. The other thing is that i can, and have gotten
    rid of it by getting rid of the text befor the php include code which isn't a solution becasue i
    want to keep the meta's and title on the page. this is what the garbage looks li...
  18. Write Random Text To Image - PHP script help! (5)
    I'm trying to create a script that writes text to an image. CODE
    header("Content-type: image/png"); $_phrases = array( "Test 1",
    "Test 2", "Test 3", "Test 4", "etc." ); $_rand_phrase =
    $_phrases[rand(0,count($_phrases)-1)]; $_image =
    imagecreatefrompng("gmail.png"); $_user_width =
    imaagettfbbox(9,0,"tahoma.ttf",$_rand_phrase); $_x_value =
    (200-($user_width[2] + 113)); ...
  19. Many Php Script Sites - (13)
    Hi I find many sites has PHP scripts :: http://www.proxy2.de/scripts.php http://www.free-php.net
    http://knubbe.t35.com/ http://www.ngcoders.com/ http://www.oxyscripts.com/
    http://www.phparena.net/ http://www.1phpstreet.com/ http://px.sklar.com/
    http://www.scoznet.com/ http://php.resourceindex.com/ /blink.gif' border='0'
    style='vertical-align:middle' alt='blink.gif' /> ...
  20. Php Dynamic News Updating Using Mysql - changing a sites news using MySQL and PHP (3)
    Hey everyone. It appears to me that everyone really know what they are doing in this forum and im a
    pretty new to this PHP and MySQL combo. I know some PHP but not MySQL....I am trying to make a new
    website but i want to be able to go to a certain update page and change the news on the main index.
    For example: - The main page show news updates of the last 10 post. - I go to the update page
    and then fill in the form and it will add this post to the top of the list and still only print the
    top 10. I have no clue how to do this with MySQL. At the moment i am doing it u...



Looking for simple, text, counters, counters, wap, sites

Searching Video's for simple, text, counters, counters, wap, sites
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE