IPB

Welcome Guest ( Log In | Register )



Tags
1    
5 Pages V   1 2 3 > »   
Reply to this topicStart new topic

Php Unique Hit Counter

, Count page hits with php.


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



Post #1 post Mar 7 2005, 11:12 PM
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
no avatar
It's Miller Time
********
Group: Members
Posts: 168
Joined: 8-February 05
Member No.: 3,672



Post #2 post Mar 8 2005, 02:44 AM
wow, thats a really short and simple script... thanks
Go to the top of the page
+Quote Post
NotoriousZach
no avatar
Member [Level 1]
****
Group: Members
Posts: 55
Joined: 26-February 05
Member No.: 3,996



Post #3 post Mar 8 2005, 03:17 AM
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
no avatar
Super Nuclear Advanced Member
*********
Group: Members
Posts: 720
Joined: 30-October 04
From: Texas
Member No.: 2,058
myCENT:61.10



Post #4 post Mar 8 2005, 03:30 AM
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
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 30-October 04
From: Philippines
Member No.: 2,049



Post #5 post Mar 8 2005, 04:48 AM
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
no avatar
Super Nuclear Advanced Member
*********
Group: Members
Posts: 720
Joined: 30-October 04
From: Texas
Member No.: 2,058
myCENT:61.10



Post #6 post Mar 8 2005, 01:10 PM
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
no avatar
Super Member
*********
Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



Post #7 post Mar 9 2005, 10:55 PM
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
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 30-October 04
From: Philippines
Member No.: 2,049



Post #8 post Mar 10 2005, 04:51 AM
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
[right][snapback]58225[/snapback][/right]

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
no avatar
Super Member
*********
Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



Post #9 post Mar 10 2005, 09:21 PM
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
+Quote Post
karlo
no avatar
Privileged Member
*********
Group: Members
Posts: 629
Joined: 30-October 04
From: Philippines
Member No.: 2,049



Post #10 post Mar 11 2005, 09:58 AM
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
[right][snapback]58596[/snapback][/right]

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?
Go to the top of the page
+Quote Post

5 Pages V   1 2 3 > » 
Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   13 KooL 14,361 31st August 2004 - 10:08 AM
Last post by: Too_Hot
No new   21 dask 18,673 26th January 2009 - 10:14 PM
Last post by: -Sky-
No New Posts   4 gpinvest 1,925 29th October 2009 - 03:29 AM
Last post by: iG-
No New Posts   9 KooL 11,670 2nd April 2009 - 11:04 AM
Last post by: varalu
No New Posts   1 tomecki 4,176 31st August 2004 - 08:52 PM
Last post by: neeki4444
No new   15 -prodigy- 14,130 27th February 2005 - 10:22 PM
Last post by: alexia
No New Posts   5 blackhawk 6,177 31st August 2004 - 01:13 PM
Last post by: Spectre
No New Posts   3 Saint_Michael 1,040 3rd June 2006 - 07:33 AM
Last post by: Avalon
No New Posts   2 ZorBiX 4,105 28th October 2004 - 09:14 AM
Last post by: ZorBiX
No new   34 MercifulFate 17,733 16th March 2005 - 07:26 PM
Last post by: AboveZero
No New Posts   3 outbreak 4,915 8th March 2005 - 10:21 PM
Last post by: Benz1435
No New Posts   4 sithslayer 3,920 14th December 2008 - 02:29 PM
Last post by: sithslayer
No New Posts   3 cragllo 7,859 2nd May 2009 - 07:55 PM
Last post by: webishqiptar
No New Posts   0 DoomTiger 2,858 18th December 2004 - 10:21 AM
Last post by: DoomTiger
No new   17 DoomTiger 6,340 8th January 2005 - 02:58 PM
Last post by: mrkill47


 



RSS Open Discussion Time is now: 6th November 2009 - 09:28 PM

Web Hosting Powered by ComputingHost.com.