我正在使用 php 记录我的网站访问者的 IP 地址以及一些其他信息 ($content),以便我可以计算访问者的数量。
我正在使用以下代码:
<?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) {
}
}
?>
这段代码工作正常。通常,我有如下条目:
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
这是类似于针对 Java 的 MySQL 注入的某种恶意注入攻击吗?
我是否需要留意任何可疑情况并修补我的 Apache 服务器以提高安全性?
哈士奇WWW
繁华开满天机