May 13, 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
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

 

 

 


Reply

millertime
wow, thats a really short and simple script... thanks

Reply

NotoriousZach
Yeh is really nice, im gonna test it out, i alrady have one that just counts page hits, one that counts unique page hits, EVEN BETTER!

Reply

rejected
Very nice! All of the other ones I've seen are very complex and I have no idea what they mean, but I understand this one. Do you mind if I use it on my site?

Reply

karlo
Do you think that we must use Cookies to make a UNIQUE COUNTER SCRIPT? What do you think?

Reply

rejected
I just added it to my site, but it's not unique hits. sad.gif

Reply

maddog39
It counts unique. The first couple hits are counted as page views till it kicks in. try it on my site at the bottum of the page. http://gamerspub.trap17.com biggrin.gif

Reply

karlo
QUOTE(maddog39 @ Mar 10 2005, 06:55 AM)
It counts unique. The first couple hits are counted as page views till it kicks in. try it on my site at the bottum of the page. http://gamerspub.trap17.com biggrin.gif
*


Well, here's what happened.

I visited your website. After that, I saw the counter. Then I reloaded the page. It stays the same. Then I reloaded it again, then the counter increased by +1. After that, I reloaded and reloaded the page again. It stays the same. Then I went to http://gamerspub.trap17.com/hits.txt and I saw many logs of my ip address.

You must use cookies() in order for it to work well. Or sessions.

 

 

 


Reply

maddog39
In my book thats not needed and it makes things complicated. It can mis count thats true. However its sensitive in different ways. So what you said depends. biggrin.gif

Reply

karlo
QUOTE(maddog39 @ Mar 11 2005, 05:21 AM)
In my book thats not needed and it makes things complicated. It can mis count thats true. However its sensitive in different ways. So what you said depends. biggrin.gif
*


Ok, maybe i'll try to modify your code and improve it. Don't worry, i'll put your copyright. Can you please add some comments and explaination to your code and add it again here, in your thread?

Reply

Latest Entries

flashy
thats good but if 50,000 odd pageviews a day were to see your site then 'hits.txt' would be around 150mb by the end of the month - the best way is to use cookies or a database. Or what you can do is check to see if the ip is already logged in the text file - if it is in there, dont write it smile.gif

Reply

tracdoor
Thanks for this, i was going mad with my last host, login scripts, counter scripts, until i realised they had safe mode on, so they didn't allow the inclution of files dry.gif

I spent hours trying to figure out what was wrong.

*whoop*whoop* for trap17 smile.gif

Reply

Trap FeedBacker
this scipt dosent work for more tahn 4 times
Php Unique Hit Counter

This script is not working for more than 4 times after that echo remains

Same check it



-reply by kar32

Reply

lailai
Thats good, with some _bugs_ anyway that's a really simple script! Thank you

Reply

Saint_Michael
Did you make sure you did the following:

-Save and upload all files to the same directory
-make sure the page that has the counter is ending with the .php extension because that is hte only way to get it running.

If your looking for more ways to set up a counter check out pixel2life.com or check out this unique hit counter script. As it is very customizable to fit with your site and works the same way this script does with flat files and no DB's.

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. hit counter unique ip - 0.24 hr back.
  2. php script for page view counts - 2.78 hr back.
  3. unique visitor counter script free html - 3.00 hr back.
  4. page hits php - 3.29 hr back.
  5. php query hit counter - 6.52 hr back.
  6. count unique hits ip address dates - 8.84 hr back.
  7. php counter check ip address - 13.18 hr back.
Similar Topics

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

  1. How To Create Counter-strike 1.6 Server In Console Mode
    (5)
  2. 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....
  3. 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.
    ?>....
  4. 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