Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

Php Programming Code Examples

Php > Statistics and Counters Code Examples

Adv. Log file generator

Adv. Log file generator <?php $date = gmdate("d/m/Y - H:i:s T"); //change to preffered format. $logstring = $date.",".$HTTP_SERVER_VARS['REMOTE_ADDR'].",".$HTTP_SERVER_VARS['HTTP_REFERER'].",".$HTTP_SERVER_VARS['HTTP_USER_AGENT']."\r"; $regexp = strtoupper("yell.co.uk"); //String to filter for. $filename = "./reflog.csv"; /* No cache!! */ $goto = "http://www.yoursite.com/main.html"; header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 /* End of No cache */ function viewlog($filename) { $fp = fopen($filename,"r"); $file = fread($fp,65535); $replaced = eregi_replace(",", "<td>", $file); $replaced2 = eregi_replace("\n", "<tr><td>", $replaced); $replaced3 = eregi_replace("\r", "<tr><td>", $replaced2); fclose($fp); return $replaced3; } if(isset($view)) { echo "<html><head><base href=\"./\"><title>Referer Log</title></head><body bgcolor=silver>"; echo "<table border=0 bordercolor=black cellspacing=0 cellpadding=5 width=100% style='font-size:10pt'><tr><td><b>Date & Time</b><td><b>IP No.</b><td><b>Referring page</b><td><b>user agent</b><tr><td>"; echo viewlog($filename); echo "</table></body></html>"; exit; } else if (ereg($regexp, strtoupper($HTTP_SERVER_VARS['HTTP_REFERER']))) { $fp=fopen($filename, "a"); if(!$fp) die ("Error opening file"); fwrite($fp, $logstring); fclose($fp); } header("Location: $goto"); ?>