Nov 21, 2009
Pages: 1, 2, 3, 4, 5

Php Unique Hit Counter - Count page hits with php.

free web hosting

Read Latest Entries..: (Post #49) by iGuest on Nov 20 2009, 05:13 PM.
php script Php Unique Hit Counter Replying to maddog39I found that this script will not work until you rename your home page or (index.Htm) to index.Php Ken
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > MODERATED AREA > Tutorials

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

 

 

 


Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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!

Comment/Reply (w/o sign-up)

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?

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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.

 

 

 


Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

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?

Comment/Reply (w/o sign-up)

Latest Entries

iGuest
php script
Php Unique Hit Counter

Replying to maddog39I found that this script will not work until you rename your home page or (index.Htm) to index.Php

Ken


Comment/Reply (w/o sign-up)

iGuest
It should be accurate
Php Unique Hit Counter

In simple, If you are going to be using a counter on your site...
It should be accurate from the first visit, Other wise what is the point of it?

-reply by MayhemOfHell

Comment/Reply (w/o sign-up)

blackout69
cool!

Comment/Reply (w/o sign-up)

iGuest
"\n" not "\and"
Php Unique Hit Counter

Replace "\and" with "\n" in the line:

array_push($file,getenv("REMOTE_ADDR")."\n");

I don't know why this came out wrong...

-reply by rookie

 


Comment/Reply (w/o sign-up)

iGuest
A simple change
Php Unique Hit Counter

I made a few changes to the script above. Maybe some will find it helpful...

This script locks the file hints.Txt to make sure you wont lose a visitor if two hit the page at the same time and the script saves only unique IPs. 

So, here it is:

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

$fp = fopen($filename,"r+");
If(flock($fp,LOCK_EX))
{
        $file = file($filename);
        array_push($file,getenv("REMOTE_ADDR")."\and");
        $file = array_unique($file);
        $hits = count($file);
        echo "($hits)";

        $filestr = implode("",$file);
        ftruncate($fp,0);
        fwrite($fp,$filestr);

        flock($fp, LOCK_UN);
}
Else
{
        print "(?)";
}
Fclose($fp);
?>

-reply by Rookie

 


Comment/Reply (w/o sign-up)



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*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2, 3, 4, 5
Similar Topics

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

  1. How To Make Your Own Counter Strike Source Dedicated Server!
    (67)
  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
    hlds.ex....
  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 counter! ';   }   echo number_format($count).' Hits'; ?> open n....
  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 // 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. ?> 1. selecting a file which the script is going to use for counting visits. 2.
    reading from the script 3. adding 1 to the number in the .txt file. 4. opening....
  5. Clicks Counter
    With PHP + MySQL (1)
    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
See Also,
advertisement


Php Unique Hit Counter - Count page hits with php.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com