which is the better way to get the ip

前端 未结 6 1202
闹比i
闹比i 2020-12-21 05:30

What is the better way of getting the IP address in PHP:

getenv(\'REMOTE_ADDR\'); 

or,

$_SERVER[\'REMOTE_ADDR\'];
         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 05:32

    getenv() can be used to access any environment variables (PHP simply registers REMOTE_ADDR as an environment variable for the script), while with $_SERVER you obviously only access the contents of the $_SERVER superglobal.

    The common approach is to use $_SERVER for this, although it doesn't really make a difference functionality-wise.

提交回复
热议问题