With $_SERVER['REMOTE_ADDR'] you read the global variable directly, referring to the $ _SERVER [] array, which is configured when a remote request occurs:
$ _ SERVER is an array containing information such as the headers, paths, and locations of the script. The entries in this array are created by the web server. There is no guarantee that each web server will provide any of these; servers may omit some or provide to others not listed here. However, a large number of these variables are considered in the "CGI 1.1" specification, so you can expect them.
The getenv () function accesses any environment variable to get the corresponding value!
In both cases, you get the same value and the same variable ... but $ _SERVER is the assembly in the PHP superglobal variable, and getenv () gets the value of the variable defined in the current environment!
I think that in this case, using a superglobal variable is the best way to get the IP address!
source share