Welcome to Virtual Tutorial World Guest!



Unique Hits Counter

 
Post new topic   Reply to topic    VTW Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Please Register and Login to this forum to stop seeing this advertsing.





Tokens:


Posted:     Post subject:

Back to top
computergeek67
Administrator
Administrator


Joined: 31 Jul 2007
Posts: 144


Tokens: 147
Location: US

PostPosted: Thu Nov 08, 2007 6:31 pm    Post subject: Unique Hits Counter Reply with quote

Open Notepad, create a blank document called hits.txt. Now upload it to you website directory, make sure to put it in the same folder as the php page containing the hits code.
Also Note: You must CHMOD this file to 777 - This simply means that it doesn't need specific permissions for the file to execute.

Add the following code to a blank file and call it counter.php.
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);
?>


This simply tells it to add 1 page view per IP, meaning it counts the amount of unique visitors you get.
This is then written to the hits.txt file and increases every time the page is loaded by an alternative IP address.

Now to make this counter show up simply add the following code on any .php page:
Code:
<b>Unique Visitors:</b> <?php include("url/to/file/counter.php"); ?>


NOTE: Remember to change url/to/file/counter.php to the correct path of your counter.php file.

-The Anizone



_________________



Come to me if you have any questions
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    VTW Forum Index -> PHP All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Card File  Gallery  Forum Archive
Powered by phpBB © 2001, 2005 phpBB Group
Virtual Tutorial World ©2007-2008 computergeek67

Affiliates