Home >Backend Development >PHP Tutorial >How to get user IP in php when using nginx server
I recently came across HTTP_X_REAL_IP and checked the information.
$_SERVER['REMOTE_ADDR'];What you get is the address of the server
$_SERVER['HTTP_X_REAL_IP'];What you get is the address of the client
Set in nginx:
proxy_set_header proxy_add_x_forwarded_for;
The backend program can get the HTTP_X_REAL_IP from the Server variable Get the user's IP address from HTTP_X_FORWARDED_FOR.
The value of HTTP_X_REAL_IP is the user REMOTE_ADDR obtained by nginx
The above has introduced the method of obtaining the user's IP in PHP when using the nginx server, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.