problem with $_SERVER['REMOTE_ADDR']

前端 未结 3 2083
情话喂你
情话喂你 2021-01-16 11:56

i used $_SERVER[\'REMOTE_ADDR\'] and it returns client ip address (IP address from which the user is viewing the current page) but at now (and same code) it returns host ip

3条回答
  •  情深已故
    2021-01-16 11:58

    I have to mention that the array key is case-sensitive, and should be upper-case:

    var_dump($_SERVER['remote_addr']);
    echo "\n";
    var_dump($_SERVER['REMOTE_ADDR']);
    

    Output:

    Notice: Undefined index: remote_addr in /home/adam/public_html/2011/01/04/foo.php on line 3
    NULL
    
    string(15) "10.0.1.51"
    

    I would var_dump($_SERVER) just to evaluate the state of your world, and go from there.

提交回复
热议问题