IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
4 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
{([Mod])}
*********
Group: Members
Posts: 710
Joined: 30-October 04
From: Texas
Member No.: 2,058



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: 623
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
{([Mod])}
*********
Group: Members
Posts: 710
Joined: 30-October 04
From: Texas
Member No.: 2,058



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: 623
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: 623
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

4 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 1,743 31st August 2004 - 10:08 AM
Last post by: Too_Hot
No new   19 dask 1,305 4th August 2004 - 05:01 AM
Last post by: zyklon
No New Posts   2 gpinvest 865 19th July 2006 - 12:10 PM
Last post by: Florisjuh
No New Posts   6 KooL 387 21st September 2004 - 11:13 PM
Last post by: odomike
No New Posts   1 tomecki 1,128 31st August 2004 - 08:52 PM
Last post by: neeki4444
No new   15 -prodigy- 1,697 27th February 2005 - 10:22 PM
Last post by: alexia
No New Posts   5 blackhawk 553 31st August 2004 - 01:13 PM
Last post by: Spectre
No New Posts   3 Saint_Michael 430 3rd June 2006 - 07:33 AM
Last post by: Avalon
No New Posts   2 ZorBiX 491 28th October 2004 - 09:14 AM
Last post by: ZorBiX
No new   34 MercifulFate 4,758 16th March 2005 - 07:26 PM
Last post by: AboveZero


 



RSS Lo-Fi Version Time is now: 4th December 2008 - 01:45 AM