How to obtain the real IP address of the client using php
Function getIp (){
If (getenv ("HTTP_CLIENT_IP") & strcasecmp (getenv ("HTTP_CLIENT_IP"), "unknown "))
$ Ip = getenv ("HTTP_CLIENT_IP ");
Else
Obtaining the Client IP address is not a simple task. Because of IP Spoofing and proxy problems, obtaining the Client IP address authenticity will be compromised and cannot be accurate. however, we try to find a perfect method to obtain the real IP
Someone asked me on the internet how to disable ip access in php. through tests, I found that the following code is good and the principle is relatively simple.
// Add IP address access restrictions
If (getenv ('http _ CLIENT_IP ') & strcasecmp
Analysis of several PHP client IP addresses: no proxy server is used, transparent proxy server is used, normal anonymous proxy server is used, fraudulent proxy server is used, and high anonymous proxy server is used. In this article, we will
Php code for restricting access from a single IP address and ip address segment
I will share two pieces of php code that limits IP address access. There are two examples of code: restrict access from a single IP address and restrict access
Someone asked me on the internet how to disable ip access in php. through tests, I found that the following code is good and the principle is relatively simple.
// Add IP address access restrictions
If (getenv ('http _ CLIENT_IP ') & strcasecmp
Asp function code:Copy codeThe Code is as follows:Function checkip (checkstring) 'uses regular expressions to determine whether the IP address is valid.Dim re1Set re1 = new RegExpRe1.pattern = "^ [0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1,
Asp function code:
Copy codeThe Code is as follows: function checkip (checkstring) 'uses regular expressions to determine whether the IP address is valid.
Dim re1
Set re1 = new RegExp
Re1.pattern = "^ [0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1, 3 }. [0-9
Implemented the function code for CDN to obtain the real IP address of the user (PHP and Asp settings ). Asp function code: The copy code is as follows: functioncheckip (checkstring) uses regular expressions to determine whether the IP address is
Asp obtains the code of the real IP address, and obtains the asp function code normally if there is no proxy, first-level or multi-level proxy in the environment test:
The code is as follows:
Function checkip (checkstring) 'uses regular
The simplest way to get the client IP address is to directly use REMOTE_ADDR, but this kind of IP address cannot be obtained if there is a proxy IP address, so we need to use HTTP_X_FORWARDED_FOR to obtain it, next, I will introduce you to a
It mainly determines whether the client uses a proxy. Pay attention to the judgment order and first determine whether the client uses the proxy http_x_forwarded_for.
Function get_onlineip (){
$ Onlineip = '';If (getenv ('HTTP _ client_ip ') &
1
2 // Example use of getenv ()
3 $ ip = getenv ('remote _ ADDR ');
4 // Or simply use a Superglobal ($ _ SERVER or $ _ ENV)
5 $ ip = $ _ SERVER ['remote _ ADDR '];
6?>
This is the method provided by manual, the official PHP website.
However, when
Php function to obtain the online ip address and client ip address
/**
* Obtain the client ip address
* @ Return [string] [description]
*/
Function getclientip (){
$ Ip = null;
If
PHP obtains the client IP address. 1? Php2Exampleuseofgetenv () 3 $ ipgetenv (REMOTE_ADDR); 4 OrsimplyuseaSuperglobal ($ _ SERVERor $ _ ENV) 5 $ ip $ _ SERVER [REMOTE_ADDR]; 6? This is in the official PHP manual mention 1
2 // Example use of getenv
Cause:
My colleague's friend's sister wants to participate in any voting activity and wants me to help brush the ticket. I agreed with my research attitude. I would like to share with you the ideas on ticket swiping.
Thoughts:
First, websites
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.