which is the better way to get the ip

前端 未结 6 1201
闹比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:51

    There's no differences between the tho calls. As you can see PHP manual use both method in the same example. There are some cases where you don't have global variables like $_SERVER enabled and you are forced to use getenv(). In my experience i've never seen a server with global variables disabled.

提交回复
热议问题