Loading...


bookmark - Php Unique Hit Counter Count page hits with php.

Php Unique Hit Counter - Count page hits with php.

 
 Discussion by maddog39 with 54 Replies.
 Last Update: March 17, 2012, 1:41 pm (View Latest)
Page 1 of 2 pages.
bookmark - Php Unique Hit Counter Count page hits with php.  
Quickly Post to Php Unique Hit Counter Count page hits with php. w/o signup Share Info about Php Unique Hit Counter Count page hits with php. using Facebook, Twitter etc. email your friend about Php Unique Hit Counter Count page hits with php. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print


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. :D :D

   Mon Mar 7, 2005    Reply         

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

   Mon Mar 7, 2005    Reply         

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!

   Mon Mar 7, 2005    Reply         


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?

   Mon Mar 7, 2005    Reply         

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

   Mon Mar 7, 2005    Reply         

I just added it to my site, but it's not unique hits. :D

   Tue Mar 8, 2005    Reply         


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

   Wed Mar 9, 2005    Reply         

QUOTE (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 :angry:


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.





   Wed Mar 9, 2005    Reply         

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. :angry:

   Thu Mar 10, 2005    Reply         

QUOTE (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. :angry:


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?

   Fri Mar 11, 2005    Reply         

Okaay here si the code with added comments. Here is counter.php.

CODE


<?php
//The file where IPs are logged.
$filename = "hits.txt";

//Counting the hits from hits.txt.
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

//Writing the IPs to the file hits.txt
$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);
?>
I think that should clear some things up. Also I will add a cookie system since that would probably be the best for this since cookies are not deleted and easier to do than sessions. :angry:

   Sat Mar 12, 2005    Reply         

QUOTE (maddog39)

Okaay here si the code with added comments. Here is counter.php.

CODE


<?php
//The file where IPs are logged.
$filename = "hits.txt";

//Counting the hits from hits.txt.
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

//Writing the IPs to the file hits.txt
$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);
?>
I think that should clear some things up. Also I will add a cookie system since that would probably be the best for this since cookies are not deleted and easier to do than sessions. :angry:

Please, more expaination... while reading your script, i learned a new function, and i didn't know that it exists, the array_unique() function. Please explain all of what's happening.

   Sat Mar 12, 2005    Reply         

Okay, first it looks at the filename and gets that. Then it counts all of the logged hits in hits.txt and displays it. After that it counts the new hits from the person coming in and writes them to hits.txt to be logged. Does that clear it up anymore? :angry:

   Sat Mar 12, 2005    Reply         

Thank ;you maddog.the script I have added to my page.It works good.

   Sat Mar 12, 2005    Reply         

QUOTE (maddog39)

Okay, first it looks at the filename and gets that. Then it counts all of the logged hits in hits.txt and displays it. After that it counts the new hits from the person coming in and writes them to hits.txt to be logged. Does that clear it up anymore? :angry:


More explaination... Especially, the section where it finds the ip address, and if it's found, then what will really happens after that?

Anyways, check out my new website http://www.karlo.ph.tc

Oh yeah, do you know any free providers that supports the changing of name servers? like the one in uni.cc like a dns service...

   Mon Mar 14, 2005    Reply         

For dynamic DNS which uses the IP address in your cPanel the only ones I know of are http://www.cjb.net and http://yi.org they are both really short DNS, FREE dns domains. :angry:

   Tue Mar 15, 2005    Reply         

QUOTE (maddog39)

For dynamic DNS which uses the IP address in your cPanel the only ones I know of are http://www.cjb.net and http://yi.org they are both really short DNS, FREE dns domains. :angry:


Hello. I think yi.org and cjb.net dosen't support name servers. I only know uni.cc and 1dni.com do you know any other?

   Tue Mar 15, 2005    Reply         

QUOTE (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. :)  :)




I just analysed this tutorial and it works, u could have added more choices for the php to read because it might get confused on what to do, remember it needs the right thing to do or it will not work, lol, and the way u designed it is for babies, you used very old php, and the syntax is a bit corrupted and rusty but it can be fixed with a little bit of elbow greese

   Fri Mar 18, 2005    Reply         

wow! now i don't think i need to sign up for counters anymore!!! thank you mucho grande!!

   Fri Mar 18, 2005    Reply         

de nada

umm.. karlo it doesnt really matter. Just login to your cPanel and where it says account stats or something, there should be an IP address other than yours. Put that IP in there and point your URL on the dynamic DNS in addon domains in cPanel also. An example is my site. http://gamerspub.cjb.net

That should help you out some. :)

   Fri Mar 18, 2005    Reply         

thanx, I'm going to use this script on my page. wanted a counter on it. so this one it will be.

   Wed Mar 23, 2005    Reply         

Than you!

   Fri Mar 25, 2005    Reply         

It won
Php Unique Hit Counter

I put it in and do what it says, but there's no counter or anything like that. Even when I load up hits.Txt it's still blank.

-question by G-Money

   Tue Apr 1, 2008    Reply         

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.

   Wed Apr 2, 2008    Reply         

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

   Thu Apr 3, 2008    Reply         

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

   Sat Apr 5, 2008    Reply         

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 ^_^

I spent hours trying to figure out what was wrong.

*whoop*whoop* for trap17 :P

   Mon Apr 7, 2008    Reply         

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 ^_^

   Sat Apr 19, 2008    Reply         

This is...


....VERY helpful!

Now I can, When my website is functional keep track of how many ppls who have visited my page / downloaded my program..

THANKS a LOT
//Datanizze

   Sun Jun 8, 2008    Reply         

size of hits.txt
Php Unique Hit Counter

Hi.. Easy installation and very straightforward.. However, is there any mod that can be done so that the hits.Txt file does not get too big. Thanks in advance... John

-reply by john

   Thu Aug 28, 2008    Reply         

Quickly Post to Php Unique Hit Counter Count page hits with php. w/o signup Share Info about Php Unique Hit Counter Count page hits with php. using Facebook, Twitter etc. email your friend about Php Unique Hit Counter Count page hits with php. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print


Similar Topics:

Php Hit Counter

All you do is copy this code into the page you want to display it on. CODE<?php $counterfile = "counter.txt"; $counter = file("$counterfile"); $c = $counter[0]; if (strlen($c) == 0 ...more

   06-Dec-2004    Reply         

Free Site Counter Stats

hi frnds everyone want to keep an eye on their site traffic. histats is a really great one i found with gives site stats for free. it have many amazing features. visit www.histats.com i am sure u will like it... this is my first ...more

   30-Nov-2007    Reply         

I Want A Good Hit Counter

hi, i want you guys to suggest me a good hit counter. i already got a one using java script but it may be not very accurate. a few days ago, i used this wordpress plugin ( CHICKUN COUNT REPORTING ). it is a hit counter for the whole website and for a certain page, it gives me more accurate results. ...more

   04-Apr-2010    Reply         

Shoutbox, Made Easy! Again! with another version!   Shoutbox, Made Easy! Again! with another version! (2) (20) Php Emailer/contact System An email or contact system for your site  Php Emailer/contact System An email or contact system for your site