I made a hit log script, and it logs the hits fine, but when I use the function to view the hit log, it crashes PHP. it used to work when I used a seperate file to read the hit log, but when I turned over to using get variables to do different things without alot of files in the hit log, when I try to view it, it crashes PHP, could you please help me?
here is the code:
<?php
//this script is copyright (c) Ben V. 2003 all rights reserved
//you may use this script as long as you keep this message in tact
$hitfile = "hitlog.dat";
if(isset($_GET['view'])){
if ($_COOKIE['cookie'] == "blah"){
$size = filesize("hitlog.dat");
$crc = crc32($hitfile);
$md5 = md5($hitfile);
include("header.php");
echo "hitlog.dat is ".$size." bytes (".round($size / 1024, 2)." kb) <br /> the md5 of ".$hitfile." is ".$md5." (origional is 99afbc940590cd2891056cd359223bcc) <br /> and the crc check is ".$crc." (origional is 1132191766)<br /><br />";
$phile = fopen("hitlog.dat", "r+");
$read = fread($phile, "9999999");
echo "<html><head><title></title></head><body>";
echo $read;
echo "</body></html>";
fclose($phile);
include("footer.php");
} else {
include("header.php");
echo "You dont have the cookie!<a href=cookie.php> COOOOOOOKIEEEEEE</a>";
include("footer.php");
}
} else {
#check to see if I am accessing my page so it doesnt take up alot of space with my own hits
if($_SERVER['REMOTE_ADDR'] == "192.168.0.3" || $_SERVER['REMOTE_ADDR'] == "127.0.0.1" || $_SERVER['REMOTE_ADDR'] == "192.168.0.2"){
setcookie ("cookie", "173898968441857", time()+60*60*24);
} else {
setcookie ("cookie", "", "-1"); //if not, make sure the cookie that allows me to do certian admin functions to be expired, and nothing.
//echo date("m-d-y h:i:s A");
$usrip = $_SERVER['REMOTE_ADDR']; //assign the IP to a variable
$browser = $_SERVER['HTTP_USER_AGENT']; //user agent (OS, Browser, other info)
$host = gethostbyaddr($usrip); //get the host addres
$ref = getenv("HTTP_REFERER"); //referrer
$date = date('m-d-y h:i:s A'); //the date and time of the hit
$self = $_SERVER['PHP_SELF']; //the page accessed (this is an included file, you know)
#################################
#put the IP and stuff into the log:
#################################
//get old contents
$read = fopen($hitfile, "r");
flock($read, LOCK_EX);
$old_cont = fread($read, 99999);
flock($read, LOCK_UN);
fclose($read);
//clear the file
$bob = fopen($hitfile, "w");
fclose($bob);
//write new contents
$log = fopen($hitfile, 'a'); //Open the data file
flock($log, LOCK_EX);
fwrite($log, $date."<br />\n"); //write the date and time
fwrite($log, "IP: ".$usrip."<br />\n"); //write the IP
fwrite($log, "Host: ".$host."<br />\n"); //write the host
fwrite($log, "Browser: ".$browser."<br />\n"); //write the user's browser
fwrite($log, "Referer: ".$ref."<br />\n"); //referer PLEASE?!
fwrite($log, "Page accessed: ".$self."<br />\n"); //write the page that was accessed
fwrite($log, "<br />
\n");
flock($log, LOCK_UN);
fclose($log);
//write old contents
$old_write = fopen($hitfile, "a");
flock($old_write, LOCK_EX);
fwrite($old_write, $old_cont);
flock($old_write, LOCK_UN);
fclose($old_write);
}
}
?>