Fix public client IP extraction and hide duplicate footer creation date
- Enhance RequestLogger::getClientIp() with 2-pass detection prioritizing public IPs over proxy/internal IPs - Hide footer creation date when identical to modification date to prevent duplicate date display - Improve AdminAuth log helper and footer template tooltips
This commit is contained in:
@@ -25,29 +25,48 @@ class RequestLogger
|
||||
|
||||
public static function getClientIp(): string
|
||||
{
|
||||
$headers = [
|
||||
$headerKeys = [
|
||||
'HTTP_CF_CONNECTING_IP',
|
||||
'HTTP_X_REAL_IP',
|
||||
'HTTP_CLIENT_IP',
|
||||
'HTTP_X_FORWARDED_FOR',
|
||||
'HTTP_X_FORWARDED',
|
||||
'HTTP_FORWARDED_FOR',
|
||||
'HTTP_FORWARDED',
|
||||
'REMOTE_ADDR',
|
||||
];
|
||||
|
||||
foreach ($headers as $header) {
|
||||
if (!empty($_SERVER[$header])) {
|
||||
$rawIp = $_SERVER[$header];
|
||||
if (str_contains($rawIp, ',')) {
|
||||
$ips = explode(',', $rawIp);
|
||||
$rawIp = trim($ips[0]);
|
||||
}
|
||||
$rawIp = trim($rawIp);
|
||||
if (filter_var($rawIp, FILTER_VALIDATE_IP) !== false) {
|
||||
return $rawIp;
|
||||
// Pass 1: Prioritize valid PUBLIC IP addresses (skips 127.0.0.1, 10.x, 172.x, 192.168.x proxy/internal IPs)
|
||||
foreach ($headerKeys as $key) {
|
||||
if (empty($_SERVER[$key])) continue;
|
||||
|
||||
$value = $_SERVER[$key];
|
||||
$ips = str_contains($value, ',') ? explode(',', $value) : [$value];
|
||||
|
||||
foreach ($ips as $rawIp) {
|
||||
$ip = trim($rawIp);
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_SERVER['REMOTE_ADDR'] ?? 'cli';
|
||||
// Pass 2: Fallback for local development environments
|
||||
foreach ($headerKeys as $key) {
|
||||
if (empty($_SERVER[$key])) continue;
|
||||
|
||||
$value = $_SERVER[$key];
|
||||
$ips = str_contains($value, ',') ? explode(',', $value) : [$value];
|
||||
|
||||
foreach ($ips as $rawIp) {
|
||||
$ip = trim($rawIp);
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
|
||||
}
|
||||
|
||||
public static function detectVisitorInfo(string $ua, string $user = ''): array
|
||||
|
||||
Reference in New Issue
Block a user