lslqtz
2023-03-05 16:30:20 +08:00
```
if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$clientIP = $_SERVER['HTTP_CF_CONNECTING_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// Amazon CloudFront
#$clientIP = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0];
// Cloudflare
/*
$clientIPList = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); // 临时使用, 其它代理 IP 不应纳入列表.
$clientIP = $clientIPList[((count($clientIPList) > 1) ? 1 : 0)];
*/
$clientIP = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0];
} else if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$clientIP = explode(',', $_SERVER['HTTP_CLIENT_IP'])[0];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}
```
这边自己在程序里直接用的...