hi guys,
recently i've just moved to a new hosting company. my cgi doesn't work with php pages anymore, the virtual () is not working.
so, i searched the web, got this script and modified it. everything is working the same way as my previous cgi script, except that, it logs everything, even page reload.
the php script:
<?php
$logfile = "log.db";
if (file_exists($logfile)) {
$handle = fopen($logfile, "r");
$log = fread($handle, filesize($logfile));
fclose($handle);
} else {
die ("The log file doesn't exist!");
}
$log = explode("\n", trim($log));
for ($i = 0; $i < count($log); $i++) {
$log[$i] = trim($log[$i]);
$log[$i] = explode('|', $log[$i]);
}
echo "Total Entries : " . count($log);
echo '<style type="text/css">
body {
background-color: #000;
color: #ffff80;
text-align: center;
font-size: 13px
}
.wrapper {
width: 90%;
text-align: center;
margin: 0 auto;
}
a {
color: #33ccff;
text-decoration: underline;
}
a:hover {
text-decoration: none;
}
table {
width: 100%;
border-collapse: collapse;
border: 2px ridge #ccc;
text-align: center;
margin: 0 auto;
font-size: 13px
}
td {
background-color: #0f0f4f;
padding: 3px;
border: 2px ridge #ccc
}
td.a {
width: 12%;
}
td.b {
width: 28%;
}
td.c {
width: 60%;
}
</style>';
echo '<div class="wrapper"><table>';
foreach ($log as $logline) {
if ($logline['1'] == '') {
echo '<tr>';
echo '<td colspan="2"><b>' . date('D j M Y G:i:s T', $logline['2']) . '</b></td>';
echo '<td class="c">' . $logline['5'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="a"><b>IP Address</b><br />' . $logline['0'] . '</td>';
echo '<td class="b"><b>Hostname</b><br />' . $logline['4'] . '</td>';
echo '<td class="c"><b>Browser/OS</b><br />' . $logline['3'] . '</td>';
echo '</tr>';
} else {
echo '<tr>';
echo '<td class="a"><a href="' . htmlspecialchars(urldecode($logline['1'])) . '"><b>Referer</b></a>';
echo '<td class="b"><b>' . date('D j M Y G:i:s T', $logline['2']) . '</b></td>';
echo '<td class="c">' . $logline['5'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="a"><b>IP Address</b><br />' . $logline['0'] . '</td>';
echo '<td class="b"><b>Hostname</b><br />' . $logline['4'] . '</td>';
echo '<td class="c"><b>Browser/OS</b><br />' . $logline['3'] . '</td>';
echo '</tr>';
}
}
echo '</table></div>';
?>
appreciate if someone could help, thanks.