Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
trouble with a hit counter
here is the code:
<?php
$filename = "hits.html" ;
$startdate = "July 2006" ;
$ip = getenv("REMOTE_ADDR") ;
$currentip = "$ip";
$file = file($filename);
$file = array_unique($file);
$file = "$filename";
$fd = fopen ($file, "r");
$fget= fread ($fd, filesize ($file));
fclose ($fd);
$totalips = htmlspecialchars($fget);
if (preg_match ("/$ip/i", "$totalips"))
{$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo "Visitors since,<br />";
echo "$startdate: 000$hits";}
else
{
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring.$currentip."<br />";
$fout= fwrite ($fd , $fcounted);
fclose($fd);
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo "Visitors since,<br />";
echo "$startdate: $hits";
}
?>
the problem im haveing is, that it logs the ip number 1 on the same line as ip number 2, so it only gets read it as 1ip. is there a way to make it split up the ip's on to diffrent lines? ive tryed /n, but that didnt seem to work :( any suggestions would help.
this is the coding i use for a hit counter ;)
btw disable smilies lol
save this as counter.php:
<?php
$count='count.txt';
if (file_exists($count))
{
$var=fopen($count,'r+');
$visits=fread($var,filesize($count));
rewind($var);
$visits++;
fwrite($var,$visits);
fclose($var);
}
else
{
echo 'N/A';
Die();
}
$num=sprintf("%s",$visits);
print $num;
?>
now in the page which u want the hits to be displayed add this code (where u want the text to be):
<?php include('counter.php') ?>
and in tht directory make a new textfile called count.txt, and set the text to 0
hope this helps ya man