I have a index.php file that loads server details with (for example)
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
at the end of the script an jpg will be displayed.
Now I would like the index.php file to create a single html file with a table format in it where the data gets imported / written to from the index.php.
So in the end I would like to open log.html and then see all the index.php submits in a html table.
Please help.
I already tried:
$f=fopen($file, 'a');
fwrite($f,$data."
");
fclose($f);
the current situation is that the code I wrote, the output goes to the log.txt file as plain text. Every submit is added as newline.
Sorry for inconvenience, below full code:
<html>
<?php
$file = "log.txt";
$date = date("d-m-y");
$time = date("H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$user = $_SERVER['REMOTE_USER'];
$remote_usr = $_SERVER['REDIRECT_REMOTE_USER'];
$host = $_SERVER['REMOTE_HOST'];
$method = $_SERVER['REQUEST_METHOD'];
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip1=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip1=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip1=$_SERVER['REMOTE_ADDR'];
}
return $ip1;
}
$ip2 = getRealIpAddr();
$data = "Date: ".$date." ,Time: ".$time.",User:".$user.", RM user: ".$remote_usr.", Host:".$host.",IP: ".$ip.", IP2: ".$ip2.", Browser: ".$browser;
$f=fopen($file, 'a');
fwrite($f,$data."
");
fclose($f);
?>
<img src="img.JPG">
<!--http://php.net/manual/en/reserved.variables.server.php -->
</body>
</html>
----------------
i did a lot of googling, i solved my problem with the following: gen.php
<?php
$lines = file("log.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$data = array_map(function($v){
list($username, $score, $user, $user_rm, $host, $ip, $ip2, $browser) = explode("+", $v);
return [
"Date" => $username,
"Time" => $score,
"User" => $user,
"RM user" => $user_rm,
"Host" => $host,
"IP" => $ip,
"IP2" => $ip2,
"Browser" => $browser
];
}, $lines);
/* usort($data, function($a, $b){
if($a["score"] == $b["score"])
return 0;
return $a["score"] > $b["score"] ? 1 : -1;
});*/
?>
<table width="100%" border="1" >
<tr>
<td style="background-color:grey;"><b>Date</b></td>
<td style="background-color:grey;"><b>Time</b></td>
<td style="background-color:grey;"><b>User</b></td>
<td style="background-color:grey;"><b>RM User</b></td>
<td style="background-color:grey;"><b>Host</b></td>
<td style="background-color:grey;"><b>IP</b></td>
<td style="background-color:grey;"><b>IP2</b></td>
<td style="background-color:grey;"><b>Browser</b></td>
</tr>
<?php foreach($data as $user){ ?>
<tr>
<td height="100%"><?php echo $user["Date"]; ?></td>
<td><?php echo $user["Time"]; ?></td>
<td><?php echo $user["User"]; ?></td>
<td><?php echo $user["RM user"]; ?></td>
<td><?php echo $user["Host"]; ?></td>
<td><?php echo $user["IP"]; ?></td>
<td><?php echo $user["IP2"]; ?></td>
<td><?php echo $user["Browser"]; ?></td>
</tr>
<?php } ?>
</table>
and this page: index.php
<html>
<?php
$file = "log.txt";
$date = date("d-m-y");
$time = date("H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$user = $_SERVER['REMOTE_USER'];
$remote_usr = $_SERVER['REDIRECT_REMOTE_USER'];
$host = $_SERVER['REMOTE_HOST'];
$method = $_SERVER['REQUEST_METHOD'];
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip1=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip1=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip1=$_SERVER['REMOTE_ADDR'];
}
return $ip1;
}
$ip2 = getRealIpAddr();
$data = "Date: ".$date." + Time: ".$time."+ User:".$user."+ RM user: ".$remote_usr."+ Host:".$host."+ IP: ".$ip."+ IP2: ".$ip2."+ Browser: ".$browser;
$f=fopen($file, 'a');
fwrite($f,$data."
");
fclose($f);
?>
<img src="img.JPG">
<!--http://php.net/manual/en/reserved.variables.server.php -->
</body>
</html>