here is our script
create a sub directory /data/ where the script can store the counter file: iplist.php
( this file is protected from direct acesss, so nobody will be able to read it )
say we name this script to ip_counter.php
using this link in top of any php page that would count visitors:
include( 'ip_counter.php' );
- too check how many visitors has been use this link:
<a href="ip_counter.php?view=1">Hits Counter result</a>
$view=0;
if(isset($_GET["view"]) && $_GET["view"]=="true") $view=1;
Here is our script.
I think you or someone should be able to add a special image show
if is a unique guest.
<?php
// Uncomment this following line For Debug only!
//error_reporting(E_ALL);
$ipfile="data/iplist.php";
$ip=$_SERVER["REMOTE_ADDR"];
$view=0;
if(isset($_GET["view"]) && $_GET["view"]=="true")
$view=1;
if(!is_file($ipfile) || filesize($ipfile)<22){
$iplist=fopen($ipfile,"wb");
fwrite($iplist,"<?php exit('no!'); ?>\n");
fclose($iplist);
$data="";
}else{
$iplist=fopen($ipfile,"rb");
$data=fread($iplist,filesize($ipfile));
fclose($iplist);
$data=str_replace("<?php exit('no!'); ?>\n","",$data);
}
$visits=0;
$found=0;
if(!empty($data)){
$ips=explode("\n",rtrim($data));
$visits=count($ips);
foreach($ips as $individual){
if($ip==$individual)
$found=1;
}
}
if(!$found){
$iplist=fopen($ipfile,"ab");
fwrite($iplist,$ip."\n");
fclose($iplist);
$visits++;
}
if($view)
print "Unique Visits: ".$visits;
?>