I have a stat counter for my website, but I do not want it to count visits from my Ip address. What is the EXACT code I would insert into the code saying that my Ip address was 12.34.567.890?
The PHP counter code:
<?php
//Stat counter for xxxxxxxxxx.com.nu
$maxlines = 100; // the maximum number of lines to show
$fn = "log.txt"; // the name of the log file to create
$s = 'document.write(\'Stat Counter\')';
$host = 'xxxxxxxxxx.com.nu'; // the shortest url
// get referring page
$page = @$HTTP_REFERER;
$uarray = parse_url($page);
$refhost = $uarray["host"];
// create new file if necessary
if (!file_exists($fn)) {
$fp = fopen ($fn, "w");
$os = "0\n";
$fw = fwrite($fp, $os);
fclose($fp);
}
// read existing data
$fa = file($fn);
$nl = count($fa);
$c = $fa[0] + 1; // inc hit
// write data to file
$fp = fopen ($fn, "w");
if (flock($fp, LOCK_EX)) { //lock the file
$os = $c . "\n\n";
$fr = fwrite($fp,$os);
$ip = getenv("REMOTE_ADDR");
$os = $uarray["path"]."\t".date("D M jS g:ia")."\t$ip\t".$_GET['ref'];
$fr = fwrite($fp,$os);
if ($nl > $maxlines) { $nl = $maxlines; }
if ($nl > 1) {
for ($i = 1; $i < $nl; $i++)
$fr = fwrite($fp,$fa[$i]);
}
flock($fp, LOCK_UN); //release lock
fclose($fp);
}
//output the javascript text
echo ($s);
?>
The script on every html page that sends information to the counter:
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
var counterPath = "log/webcounter.php";
document.write("<iframe src=\""+counterPath+"\?ref="+document.referrer+"\" width=1 height=1 marginwidth=0 marginheight=0 frameborder=0 scrolling=\"no\"><\/iframe>");
</SCRIPT>
Also if you could give me a code for an even better php counter that would be nice.
Thanks
Thanks for the response, but this does not work. I receive a T_DNUMBER syntax error. Where in the code should I place this code? What I want it to do is when the php code realizes that it's my Ip address, it exits and does nothing more.
The PHP counter code:
<?php
//Stat counter for xxxxxxxxxx.com.nu
$maxlines = 100; // the maximum number of lines to show
$fn = "log.txt"; // the name of the log file to create
$s = 'document.write(\'Stat Counter\')';
$host = 'xxxxxxxxxx.com.nu'; // the shortest url
// get referring page
$page = @$HTTP_REFERER;
$uarray = parse_url($page);
$refhost = $uarray["host"];
// create new file if necessary
if (!file_exists($fn)) {
$fp = fopen ($fn, "w");
$os = "0\n";
$fw = fwrite($fp, $os);
fclose($fp);
}
// read existing data
$fa = file($fn);
$nl = count($fa);
$c = $fa[0] + 1; // inc hit
// write data to file
$fp = fopen ($fn, "w");
if (flock($fp, LOCK_EX)) { //lock the file
$os = $c . "\n\n";
$fr = fwrite($fp,$os);
$ip = getenv("REMOTE_ADDR");
$os = $uarray["path"]."\t".date("D M jS g:ia")."\t$ip\t".$_GET['ref'];
$fr = fwrite($fp,$os);
if ($nl > $maxlines) { $nl = $maxlines; }
if ($nl > 1) {
for ($i = 1; $i < $nl; $i++)
$fr = fwrite($fp,$fa[$i]);
}
flock($fp, LOCK_UN); //release lock
fclose($fp);
}
//output the javascript text
echo ($s);
?>
The script on every html page that sends information to the counter:
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript">
var counterPath = "log/webcounter.php";
document.write("<iframe src=\""+counterPath+"\?ref="+document.referrer+"\" width=1 height=1 marginwidth=0 marginheight=0 frameborder=0 scrolling=\"no\"><\/iframe>");
</SCRIPT>
Also if you could give me a code for an even better php counter that would be nice.
Thanks
Thanks for the response, but this does not work. I receive a T_DNUMBER syntax error. Where in the code should I place this code? What I want it to do is when the php code realizes that it's my Ip address, it exits and does nothing more.