Log Files

From Hostek.com Wiki
Revision as of 10:00, 22 November 2012 by Carlb (Talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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");
}
?>