📜  在 php 代码示例中获取用户 ip

📅  最后修改于: 2022-03-11 14:53:56.781000             🧑  作者: Mango

代码示例4
#to best handle proxies use this:
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}