What is the meaning of the common method for php to obtain ip addresses?

Source: Internet
Author: User
What do php commonly used methods for obtaining ip addresses mean? Problem 1: The common method to obtain ip addresses is to use the "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR", and "REMOTE_ADDR" elements in the $ _ SERVER array. What are the values of these three elements? What do I mean by common methods for getting ip addresses in php?
Question 1:
You can use the "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR", and "REMOTE_ADDR" elements of the $ _ SERVER array to obtain the ip address.
What are the values of these three elements?
I checked on the Internet:
HTTP_CLIENT_IP: indicates the client ip address.
HTTP_X_FORWARDED_FOR: ip address of the client accessing the Internet through proxy
REMOTE_ADDR: connection ip address
My understanding is:
(1) if the client is directly connected to the Internet:
HTTP_CLIENT_IP: displays the client ip address.
HTTP_X_FORWARDED_FOR: no
REMOTE_ADDR: displays the client ip address.
(2) if the client uses the proxy server:
HTTP_CLIENT_IP: no
HTTP_X_FORWARDED_FOR: displays the client ip address.
REMOTE_ADDR: displays the proxy server ip address

Is that true?


Question 2:
The client's ip information is sent through the header? Why can't I see the relevant information when I use firefox to check the header?


Thank you!

------ Solution --------------------
1. you should be right. there is a classic if statement on the internet. it can be used if necessary. However, it can only identify the gentleman and is ineffective for the villain.
2, HTTP_X_FORWARDED_FOR, this should be available. The other two REMOTE_ADDR and CLIENT_IP personally think the same thing. they are all the IP addresses obtained by accept, but they are explained based on whether there is HTTP_XFORWARDED_FOR.
------ Solution --------------------
Only REMOTE_ADDR reflects the real public network endpoint of the user.
Others are additional content of various network devices for reference only
Because they can be constructed at will.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.