Did the CDN to obtain the user real IP function code (PHP and ASP set up way) _php skill

Source: Internet
Author: User
Tags explode servervariables

ASP function Code:

Copy Code code as follows:

function Checkip (checkstring) ' uses regular to determine whether IP is legal
Dim Re1
Set Re1=new REGEXP
Re1.pattern= "^[0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}. [0-9] {1,3}$ "
Re1.global=false
Re1. Ignorecase=false
Checkip=re1.test (checkstring)
Set re1=nothing
End Function

function get_cli_ip () ' Take the real IP function, http_client_ip before Http_x_forwarded_for remote_addr
Dim client_ip
If Checkip (Request.ServerVariables ("Http_client_ip")) =true Then
Get_cli_ip = Checkip (Request.ServerVariables ("Http_client_ip"))
Else
MyArray = Split (Request.ServerVariables ("Http_x_forwarded_for"), ",")
If UBound (myarray) >=0 Then
Client_ip = Trim (myarray (0))
If Checkip (client_ip) =true Then
GET_CLI_IP = Client_ip
Exit function
End If
End If
GET_CLI_IP = Request.ServerVariables ("REMOTE_ADDR")
End If
End Function

Discuz Forum to take real IP PHP code, other similar, please refer to a little modification

(Discuz modify include/common.inc.php)
Use the following code:

Copy Code code as follows:

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 ')) {

$testip = Explode ('. ', getenv (' http_x_forwarded_for '));

if ($testip [0]== ' 192′&& $testip [1]== ' 168′) {
$onlineip = getenv (' remote_addr ');
}
ElseIf ($testip [0]== ' 10′) {
$onlineip = getenv (' remote_addr ');
}
else {
$onlineip = getenv (' http_x_forwarded_for ');
}

Gamesir hack End} 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 ')} {
by Johnny
$tmp _ip = Explode (', ', $_server[' http_x_forwarded_for ']);
$tmp _ip1 = Explode (', ', $tmp _ip[0]);
if ($tmp _ip1[0] = = ' 192′&& $tmp _ip1[1] = = ' 168′) {
$onlineip = getenv (' remote_addr ');
}else if ($tmp _ip1[0]== ' 10′) {
$onlineip = getenv (' remote_addr ');
}
else{
$ONLINEIP = $tmp _ip[0];
}
unset ($tmp _ip); unset ($tmp _ip1);

}

Replace this piece of code:

Copy Code code as follows:

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 '];
}

Related Article

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.