IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
4 Pages V  < 1 2 3 4 >  
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 #11 post Mar 12 2005, 05:47 PM
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. 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 #12 post Mar 13 2005, 02:52 AM
QUOTE(maddog39 @ Mar 13 2005, 01:47 AM)
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. biggrin.gif
[right][snapback]59073[/snapback][/right]

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.
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 #13 post Mar 13 2005, 03:24 AM
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? biggrin.gif
Go to the top of the page
+Quote Post
guangdian
no avatar
Trap Grand Marshal Member
***********
Group: Members
Posts: 1,185
Joined: 24-September 04
Member No.: 1,245



Post #14 post Mar 13 2005, 04:43 AM
Thank ;you maddog.the script I have added to my page.It works good.
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 #15 post Mar 15 2005, 04:23 AM
QUOTE(maddog39 @ Mar 13 2005, 11:24 AM)
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? biggrin.gif
[right][snapback]59270[/snapback][/right]

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...
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 #16 post Mar 16 2005, 04:06 AM
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. 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 #17 post Mar 16 2005, 04:58 AM
QUOTE(maddog39 @ Mar 16 2005, 12:06 PM)
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. biggrin.gif
[right][snapback]60516[/snapback][/right]

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?
Go to the top of the page
+Quote Post
doom145
no avatar
Advanced Member
*******
Group: Members
Posts: 117
Joined: 11-March 05
Member No.: 4,380



Post #18 post Mar 18 2005, 06:17 PM
QUOTE(maddog39 @ Mar 8 2005, 12:12 AM)
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
[right][snapback]57363[/snapback][/right]



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
Go to the top of the page
+Quote Post
thebluekirby
no avatar
Super Member
*********
Group: Members
Posts: 421
Joined: 17-January 05
From: Somewhere over the rainbow
Member No.: 3,317



Post #19 post Mar 18 2005, 08:32 PM
wow! now i don't think i need to sign up for counters anymore!!! thank you mucho grande!!
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 #20 post Mar 18 2005, 08:46 PM
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. biggrin.gif
Go to the top of the page
+Quote Post

4 Pages V  < 1 2 3 4 >
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


 

Display Mode: Standard ·