To prevent ip spoofing

Source: Internet
Author: User
If the following code prevents ip spoofing, it is used to obtain the client IP address: if (getenv ('http _ CLIENT_IP ') & amp; strcasecmp (getenv ('http _ CLIENT_IP '), 'unknon') {& nbsp; $ onlineip = getenv ('http _ CLIE if the ip address is not forged
Run the following code to obtain the client IP address:
If (getenv ('http _ CLIENT_IP ') & strcasecmp (getenv ('http _ CLIENT_IP'), 'Unknown ')){
$ Onlineip = getenv ('http _ CLIENT_IP ');
} Elseif (getenv ('http _ X_FORWARDED_FOR ') & strcasecmp (getenv ('http _ X_FORWARDED_FOR'), 'Unknown ')){
$ Onlineip = getenv ('http _ X_FORWARDED_FOR ');
} Elseif (getenv ('remote _ ADDR ') & strcasecmp (getenv ('remote _ ADDR'), 'Unknown ')){
$ Onlineip = getenv ('remote _ ADDR ');
} Elseif (isset ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR '] & strcasecmp ($ _ SERVER ['remote _ ADDR'], 'Unknown ')){
$ Onlineip = $ _ SERVER ['remote _ ADDR '];
}
However, all request headers starting with HTTP _ belong to messages that can be forged on the client. in the reverse proxy environment, how can I ensure that PHP will not receive forged invalid HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR values?


------ Solution --------------------
What is the relationship between reverse proxy and forged IP addresses?

IP address cannot be fraudulent. if you want to cheat, you must use a proxy server to request you. what can you do?
------ Solution --------------------
Although the IP address on the proxy or vpn is not his own, it is a genuine IP address, just like shopping, let your store buy something called Xiao Wang, he is really called Xiao Wang, when Mr. Smith leaves, I tell him that Mr. Smith is buying something for others.

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.