With the rapid rise of nginx, more and more companies to replace Apache into Nginx. At the same time, more and more people use Nginx as load balancer, and the agent may also add CDN acceleration, but also encountered a problem: how to get the user's
Want to convert IPV4 address to real address, must refer to IP database, commercial IP database stored in relational database, query and use is very convenient, but the cost is not individual and small companies willing to bear, So the idea of
PHP Get client Real IP address method$_server["REMOTE_ADDR" is often used in PHP get client IP.(1) However, if the client is accessed using a proxy server, the IP address of the proxy server is taken, not the real client IP address. To get the real
PHP Get visitors Real IP address in my time we need to get the user's real IP address, for example, log records, geo-location, user information, website data analysis, in fact, get the IP address is very simple $_server[' remote_addr '] on it.
PHP
This article introduces two functions one is to verify the IP address, the other is to obtain the user's real IP address of the function, is also commonly used two IP operation function, the need for students can refer to.
1. Get the user's real IP
This article mainly introduces the use of PHP to obtain the user client real IP method, has a certain reference value, now share to everyone, have the need for friends can refer to
Getting the client IP is not a simple job, because there are IP
I tried to use php to obtain the real IP address. many codes on the Internet won't work, but ip138 can display my real ip address every time. Thank you for your support. For example, the IP address I obtained using the common php is: 60.55.8.229 &
$_server["REMOTE_ADDR" is often used in PHP to obtain client IP.(1) But if the client is using a proxy server for access, then the IP address of the proxy server is taken, not the real client IP address. To obtain the client's true IP address
in the JSP, the method to obtain the IP address of the client is: Request.getremoteaddr (), which is valid in most cases. However, after passing the reverse proxy software such as Apache,squid,nginx, due to the addition of the middle tier between
Get an IP address function through complex judgments and counts
Copy CodeThe code is as follows:
function GetIP () {
if (getenv (' http_client_ip ')) {
$ip = getenv (' http_client_ip ');
}
ElseIf (getenv (' http_x_forwarded_for ')) {
$ip = getenv ('
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.