Home  >  Article  >  Backend Development  >  Get the visitor's client IP address

Get the visitor's client IP address

WBOY
WBOYOriginal
2016-07-29 09:14:461273browse

/**

* Get the visitor’s client IP address

*/

echo $ip = getIP();

function getIP() {
if ($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif ($_SERVER['HTTP_CLIENT_IP']){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif ($_SERVER['REMOTE_ADDR']){
$ip = $_SERVER['REMOTE_ADDR'];
}elseif (getenv('HTTP_X_FORWARDED_FOR')){
        $ip = getenv('HTTP_X_FORWARDED_FOR');
    }elseif (getenv('HTTP_CLIENT_IP')){
          $ip = getenv('HTTP_CLIENT_IP');
}elseif (getenv ('REMOTE_ADDR')){
            $ip = getenv('REMOTE_ADDR');
        }else{
                  $ip = '';
The above introduces how to obtain the visitor's client IP address, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn