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] {1, 3} $"
Re1.global = false
Re1.Ignorecase = false
Checkip = re1.test (checkstring)
Set re1 = nothing
End function
Function get_cli_ip () ': obtains the real IP address. First, HTTP_CLIENT_IP, then HTTP_X_FORWARDED_FOR, and then 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
Use the php code of the real IP address in the discuz Forum. For other similar code, see make some modifications.
(Discuz modify include/common. inc. php)
Use the following code:
Copy codeThe Code is 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] = '000000' & $ testip [1] = '000000 ′){
$ 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] = '000000' & $ tmp_ip1 [1] = '000000 ′){
$ 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 Code:
Copy codeThe Code is 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 '];
}