Welcome Guest ( Log In | Register)



3 Pages V   1 2 3 >  
Reply to this topicStart new topic
> Php Unique Hit Counter, Count page hits with php.
maddog39
post Mar 7 2005, 11:12 PM
Post #1


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



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
Go to the top of the page
 
+Quote Post
millertime
post Mar 8 2005, 02:44 AM
Post #2


It's Miller Time
********

Group: Members
Posts: 164
Joined: 8-February 05
Member No.: 3,672



wow, thats a really short and simple script... thanks
Go to the top of the page
 
+Quote Post
NotoriousZach
post Mar 8 2005, 03:17 AM
Post #3


Member [Level 1]
****

Group: Members
Posts: 55
Joined: 26-February 05
Member No.: 3,996



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!
Go to the top of the page
 
+Quote Post
rejected
post Mar 8 2005, 03:30 AM
Post #4


{([Mod])}
*********

Group: Members
Posts: 710
Joined: 30-October 04
From: Texas
Member No.: 2,058



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?
Go to the top of the page
 
+Quote Post
karlo
post Mar 8 2005, 04:48 AM
Post #5


Privileged Member
*********

Group: Members
Posts: 618
Joined: 30-October 04
From: Philippines
Member No.: 2,049



Do you think that we must use Cookies to make a UNIQUE COUNTER SCRIPT? What do you think?
Go to the top of the page
 
+Quote Post
rejected
post Mar 8 2005, 01:10 PM
Post #6


{([Mod])}
*********

Group: Members
Posts: 710
Joined: 30-October 04
From: Texas
Member No.: 2,058



I just added it to my site, but it's not unique hits. sad.gif
Go to the top of the page
 
+Quote Post
maddog39
post Mar 9 2005, 10:55 PM
Post #7


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



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
Go to the top of the page
 
+Quote Post
karlo
post Mar 10 2005, 04:51 AM
Post #8


Privileged Member
*********

Group: Members
Posts: 618
Joined: 30-October 04
From: Philippines
Member No.: 2,049



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.
Go to the top of the page
 
+Quote Post
maddog39
post Mar 10 2005, 09:21 PM
Post #9


Super Member
*********

Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



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
Go to the top of the page