I am logging my website visitor’s IP addresses along with some other information ($content) with php, so that I could count the number of visitors.
I am using the following code:
<?php
public static function logContent(array $content = null){
try {
$myFile = fopen("visitors.txt", "a");
$txt = "IP: ";
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipAddress = $_SERVER['HTTP_CLIENT_IP'];
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_X_FORWARDED']))
$ipAddress = $_SERVER['HTTP_X_FORWARDED'];
else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipAddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_FORWARDED']))
$ipAddress = $_SERVER['HTTP_FORWARDED'];
else if (isset($_SERVER['REMOTE_ADDR']))
$ipAddress = $_SERVER['REMOTE_ADDR'];
else
$ipAddress = 'UNKNOWN';
$txt .= $ipAddress;
$txt .= " Time: " . date("Y-m-d h:i:s", time());
$txt .= "n";
if (!empty($content) && is_array($content)) {
foreach ($content as $k => $v) {
$txt .= "$k : ";
$txt .= $v;
$txt .= "n";
}
$txt .= "n";
}
fwrite($myFile, $txt);
fclose($myFile);
} catch (Exception $e) {
}
}
?>
This code works fine. Normally, I have entries such as below:
IP: 36.80.227.XX Time: 2020-06-19 08:23:52
IP: 191.252.61.XX Time: 2020-06-19 11:25:02
IP: 191.252.61.XX Time: 2020-06-19 11:25:02
But, I recently got the following entry in my log.
IP:
}__test|O:21:"JDatabaseDriverMysqli":3:{s:2:"fc";O:17:"JSimplepieFactory":0:{}s:21:"