Difference between revisions of "Log Files"

From Hostek.com Wiki
Jump to: navigation, search
(Created page with "==Getting IP addresses From Site Log Files== If you need to get the lines out of the logs for a certain IP you can use the PHP code below: *NOTE: You'll need to change the $i...")
(No difference)

Revision as of 10:00, 22 November 2012

Getting IP addresses From Site Log Files

If you need to get the lines out of the logs for a certain IP you can use the PHP code below:

  • NOTE: You'll need to change the $ip and $file variables to match your needs.
<?php
header('Content-type: text/plain');
$ip = '1.2.3.4';
$file = 'D:\home\example.com\logs\W3SVC123\ex090430.log';

if ($fh = fopen($file, 'r')) {
while ($line = fgets($fh)) {
if (strpos($line, $ip) !== FALSE) {
echo $line;
}
}
} else {
die("Can't open $file for reading.\n");
}
?>