Jul 26, 2008

Php Unique Hit Counter - Count page hits with php.

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials
Pages: 1, 2, 3

free web hosting

Php Unique Hit Counter - Count page hits with php.

maddog39
Okaay here si the code with added comments. Here is counter.php.
[CODE]
<?php
//The file where IPs are logged.
$filename = "hits.txt";

//Counting the hits from hits.txt.
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

//Writing the IPs to the file hits.txt
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>
I think that should clear some things up. Also I will add a cookie system since that would probably be the best for this since cookies are not deleted and easier to do than sessions. biggrin.gif

 

 

 


Reply

karlo
QUOTE(maddog39 @ Mar 13 2005, 01:47 AM)
Okaay here si the code with added comments. Here is counter.php.
[CODE]
<?php
//The file where IPs are logged.
$filename = "hits.txt";

//Counting the hits from hits.txt.
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

//Writing the IPs to the file hits.txt
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>
I think that should clear some things up. Also I will add a cookie system since that would probably be the best for this since cookies are not deleted and easier to do than sessions. biggrin.gif
*

Please, more expaination... while reading your script, i learned a new function, and i didn't know that it exists, the array_unique() function. Please explain all of what's happening.

 

 

 


Reply

maddog39
Okay, first it looks at the filename and gets that. Then it counts all of the logged hits in hits.txt and displays it. After that it counts the new hits from the person coming in and writes them to hits.txt to be logged. Does that clear it up anymore? biggrin.gif

Reply

guangdian
Thank ;you maddog.the script I have added to my page.It works good.

Reply

karlo
QUOTE(maddog39 @ Mar 13 2005, 11:24 AM)
Okay, first it looks at the filename and gets that. Then it counts all of the logged hits in hits.txt and displays it. After that it counts the new hits from the person coming in and writes them to hits.txt to be logged. Does that clear it up anymore? biggrin.gif
*


More explaination... Especially, the section where it finds the ip address, and if it's found, then what will really happens after that?

Anyways, check out my new website http://www.karlo.ph.tc

Oh yeah, do you know any free providers that supports the changing of name servers? like the one in uni.cc like a dns service...

Reply

maddog39
For dynamic DNS which uses the IP address in your cPanel the only ones I know of are http://www.cjb.net and http://yi.org they are both really short DNS, FREE dns domains. biggrin.gif

Reply

karlo
QUOTE(maddog39 @ Mar 16 2005, 12:06 PM)
For dynamic DNS which uses the IP address in your cPanel the only ones I know of are http://www.cjb.net and http://yi.org they are both really short DNS, FREE dns domains. biggrin.gif
*


Hello. I think yi.org and cjb.net dosen't support name servers. I only know uni.cc and 1dni.com do you know any other?

Reply

doom145
QUOTE(maddog39 @ Mar 8 2005, 12:12 AM)
Hello all,

Here is a neat and helpful PHP script that can count unique page views on your website. First you need to open up a new page in your text editor and paste in this code.
CODE

<?php
$filename = "hits.txt";

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
fclose($fd);
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>

then save the page as counter.php

Next open up another new page in your text editor and just save it as hits.txt
Then upload all of the files onto your server and CHMOD hits.txt to 0777 or just 777.
After that open up your main page or the page you will be placing the counter on and pste in the following code.
CODE

<?php
include ('counter.php');
?>

then save and close that page. If needed, re-upload the file(s) to your server. Very simple and easy to use. Comments are allways appreciated. wink.gif  biggrin.gif
*




I just analysed this tutorial and it works, u could have added more choices for the php to read because it might get confused on what to do, remember it needs the right thing to do or it will not work, lol, and the way u designed it is for babies, you used very old php, and the syntax is a bit corrupted and rusty but it can be fixed with a little bit of elbow greese

Reply

thebluekirby
wow! now i don't think i need to sign up for counters anymore!!! thank you mucho grande!!

Reply

maddog39
de nada

umm.. karlo it doesnt really matter. Just login to your cPanel and where it says account stats or something, there should be an IP address other than yours. Put that IP in there and point your URL on the dynamic DNS in addon domains in cPanel also. An example is my site. http://gamerspub.cjb.net

That should help you out some. biggrin.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, 3
Recent Queries:-
  1. php count views - 6.15 hr back. (1)
  2. php unique hits counter - 6.15 hr back. (13)
  3. how to create counter coding in php - 19.73 hr back. (1)
  4. hit counter php - 16.94 hr back. (2)
  5. hit counter in php - 25.52 hr back. (1)
  6. hit count php - 26.89 hr back. (1)
  7. page hit in php - 27.47 hr back. (2)
  8. unique visitor counter php - 28.74 hr back. (1)
  9. unique hits counter - 30.67 hr back. (1)
  10. unique php hit counter - 13.26 hr back. (5)
  11. php unitque hit counter - 32.58 hr back. (1)
  12. sample code of php to count hit to server - 33.21 hr back. (1)
  13. php unique hit counter - 9.35 hr back. (5)
  14. php hit counter cookie - 33.82 hr back. (1)
Similar Topics

Keywords : php, unique, hit, counter, count, page, hits, php

  1. How To Make Your Own Counter Strike Source Dedicated Server!
    (6)
  2. How To Create Counter-strike 1.6 Server In Console Mode
    (5)
    Hello! Now I will show you how to create a CS 1.6 Dedicated server /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> 1. Locate HLDS.exe. It
    could start it from Steam. 2. Make a batch file. You could name it how you like, I writed it as
    start.bat. It should be located in the same folder as the HLDS.exe. It should contain something like
    this: CODE HLDS.EXE -console -game cstrike -port 27015 +maxplayers 24 +map bl_counterquake
    +sv_lan 0 +rcon_password yourrconpass -secure I recommend -console to be there, couse it starts
    hld....
  3. Hit Counter
    simple hit counter (14)
    ok just copy this code to the location you want the counter on PHP Code QUOTE   $file =
    'counter.txt';   if(!file_exists($file))   {       $handle =
    fopen($file, 'w');       fwrite($handle, 0);       fclose($handle);   }  
    $count = file_get_contents($file);   $count++;   if(is_writable($file))   {
          $handle = fopen($file, 'w+');       fwrite($handle, $count);    
      fclose($handle);   }   else   {       echo 'Could not increment the cou....
  4. Simple Php Counter Script
    How to make a simple php counter script (2)
    In this tutorial i will explain how to make a simple script writen in PHP...that uses .txt file.
    CODE <?php // script writen by tema $a = fopen ("count.txt",
    "r"); // 1. $bytes = 4;         $x = fread($a, $bytes); //
    2. $y=$x + 1;                   // 3. $fp = fopen ("counter/count.txt",
    "w+");  // 4. fwrite ($fp, "$y");     // 5. fclose
    ($fp);                // 6. echo "Posjeta:$y";                // 7.
    ?>....
  5. Clicks Counter
    With PHP + MySQL (0)
    Well, in this tut, I'll show you how to do an simple link counter, with only one count for each
    IP and the date when the link were clicked. Just remember, this is only one way to do it. First,
    create an mysql database called 'links', with 2 table: first table will be called
    'links', with the columns: id, title, ref and clicks. The other one will be 3 columns and
    will be called links_info: id, ip and date. Just remember that the columns 'id' of this
    second table IS NOT auto-increment. Here is the code of the file which will count the clicks, ....

    1. Looking for php, unique, hit, counter, count, page, hits, php

Searching Video's for php, unique, hit, counter, count, page, hits, php
advertisement



Php Unique Hit Counter - Count page hits with php.



 

 

 

 

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