Hi group,
I have a php script that will not work correctly unless I use it to create a HTML file. The script reads from the Apache logs and creates a web page.
That does not work right, but if I pipe the script to create a HTML file, the output is correct? The code:
Code:
<?php
#if( !isset($_GET["log"])) $Log = "access.log";
#else $Log = $_GET["log"] . ".log";
#echo "$Log";
$Sort = fopen( "sort.dat", "w" );
exec( "sudo /bin/cat /var/log/apache2/access.log.1" .
"/var/log/apache2/access.log" ,
$output, $rc );
if( $rc != 0 ) {
echo "RC: $rc\n cat failed\n<br>";
var_dump( $output );
exit; }
$Count = count( $output );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Apache Access Log</title>
</head>
<body style="background-color: rgb(204, 204, 204); color: windowtext;"
alink="#ee0000" link="#0000ee" vlink="#551a8b">
</body>
<center>
<Table border="5" width="100%" >
<tbody>
<tr>
<th>Date</th>
<th>Request</th>
<th>Code</th>
<th>Client</th>
<th>Type</th>
</tr>
<?php
$Line = array();
$Date = array();
$Day = array();
foreach($output as $Record) {
$Line = explode(" ", $Record);
$Temp = $Line[3];
$Date = explode( ":", "$Temp" );
$Time = "$Date[1]" . ":" . "$Date[2]" . ":" . "$Date[3]";
$Temp = $Line[5];
$Request = substr( $Temp, 1 );
$Day = explode( "/", "$Line[3]" );
$Day[0] = substr( $Day[0], 1 );
echo " <tr>\n"
." <td>" . "$Day[0] " . "$Time" . "</td>\n"
." <td>" . "$Request" . "</td>\n"
." <td>" . "$Line[8]" . "</td>\n"
." <td>" . "$Line[0]" . "</td>\n"
." <td>" . "$Line[6]" . "</td>\n"
." </tr>\n";
$NL = $Line[6] . "\n";
$RC = fputs( $Sort, $NL , strlen( $NL ) ); }
echo "<tr><td colspan=\"5\"><center>Count: $Count</td></tr>" .
"</tbody></table>\n";
echo "<br>List by request\n";
echo "<Table border=\"10\" width=\"100%\" ><tbody>\n";
fclose( $Sort );
exec( "sort sort.dat | uniq -c | sort -n", $Output, $rc );
foreach( $Output as $Record ) {
$Line = explode( " ", trim( $Record ) );
echo "<tr><td>" .
"$Line[0]" .
"</td><td>" .
"$Line[1]" .
"</td></tr> \n"; }
echo "</tbody></table>";
?>
</html>
The first part works OK but the second table is not outputed
for the second table if run as a php script by the Apache server. If I use this CLI:
Code:
php /WebServer/log.php > /WebServer/LOG.html
and create an HTML file, it works right?
Any ideas?
Thanks for your time.