本文介绍了如何在PHP中获取用户的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码来获取用户的真实IP地址。

I am using below code to get the user's real IP address.

function getUserIP () {

    if (getenv('HTTP_CLIENT_IP')) {

        $ip = getenv('HTTP_CLIENT_IP');

    }

    elseif (getenv('HTTP_X_FORWARDED_FOR')) {

        $ip = getenv('HTTP_X_FORWARDED_FOR');

    }

    elseif (getenv('HTTP_X_FORWARDED')) {

        $ip = getenv('HTTP_X_FORWARDED');

    }

    elseif (getenv('HTTP_FORWARDED_FOR')) {

        $ip = getenv('HTTP_FORWARDED_FOR');

    }

    elseif (getenv('HTTP_FORWARDED')) {

        $ip = getenv('HTTP_FORWARDED');

    }

    else {

        $ip = $_SERVER['REMOTE_ADDR'];

    }

    return $ip;

}

$userIP = getUserIP();

有时我知道IP地址是 67.143.220.112,67.142。 171.26

Sometimes I am getting that the IP address is 67.143.220.112, 67.142.171.26.

这是用户的正确IP地址还是我必须做其他事情才能获得用户的真实IP地址?

Is that the correct IP address of the user or do I have to do something else to get the real IP address of the user?

推荐答案

$ _ SERVER ['REMOTE_ADDR']; 给用户的IP地址。

这篇关于如何在PHP中获取用户的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:30