Home >Backend Development >PHP Tutorial >How to get user IP in php when using nginx server

How to get user IP in php when using nginx server

WBOY
WBOYOriginal
2016-07-28 08:26:451196browse

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

nginxIn proxy mode , get the real IP 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn