Get true IP of the client

xiaoxiao2021-03-06  71

Get the real IP of the client, even if the proxy server is used

After the agent, since the intermediate layer is added between the client and the service, the server cannot directly get the client's IP, and the server-side application cannot be returned directly to the client through the address of the forwarding request. However, in the HTTD header information of the forwarding request, it adds http_x_forwarded _ ???? information. Used to track the original client IP address and server address for client requests:

http://www.acnow.net/ HKJUAAPJRM

Below is 2 examples for explaining the design principle of cache and compatibility applications:

http://www.acnow.net/ AF

'For an ASP application that requires the address of the server name: Do not directly reference http_host / server_name, it is judged whether there is http_x_forwarded_server

http://www.acnow.net/ AF

Function gethostname ()

http://www.acnow.net/ AF

Dim Hostname As String = ""

http://www.acnow.net/ AF

Hostname = Request.Server

Variables ("http_host")

http://www.acnow.net/ AF

IF not isdbnull (Request.Server

Variables ("http_x_forwarded_host")))?

http://www.acnow.net/ AF

IF LEN (Trim (Request.server

Variables ("http_x_forwarded_host")))))> 0 THEN

http://www.acnow.net/ AF

Hostname = Request.Server

Variables ("http_x_forwarded_host")

http://www.acnow.net/ AF

END IF

http://www.acnow.net/ AF

END IF

http://www.acnow.net/ AF

Return Hostnmae

http://www.acnow.net/ AF

end

Function

http://www.acnow.net/ HKJUAAPJRM

/ / For a PHP application that needs to record client IP: Do not reference Remote_Addr directly, but use http_x_forwarded_for,

http://www.acnow.net/ AF

Function getUserip () {

http://www.acnow.net/ AF

$ user_ip = $ _server ["remote_addr"];

http://www.acnow.net/ AF

IF ($ _SERVER ["http_x_forwarded_for"]) {

http://www.acnow.net/ AF

$ user_ip = $ _server ["http_x_forwarded_for"];

http://www.acnow.net/ AF

}

http://www.acnow.net/ AF

}

http://www.acnow.net/ HKJUAAPJRM

http://www.acnow.net/ AF Note: HTTP_X_FORDED_FOR If you have passed multiple intermediate proxy servers, what can be a comma-divided address, http://www.acnow.net/ Af, 200.28.7.155 , 200.10.225.77 Unknown, 219.101.137.3 http://www.acnow.net/ AF So in many old database designs (such as BBS) often used to record the field address of the client address is set to 20 bytes Too small. http://www.acnow.net/HKJUAPJRM often see the following error message: http://www.acnow.net/ Afhttp: //www.acnow.net/ AF

Microsoft Jet Database Engine Error '80040E57'

http://www.acnow.net/ AF

The field is too small without accepting the number of data to be added. Try to insert or paste less data.

http://www.acnow.net/ AF

/inc/char.asp, line 236

http://www.acnow.net/ AF

The reason is that when designing client access addresses, the relevant user IP field size is best to design 50 bytes, of course, the chances of 3 or more agents are also very small.

转载请注明原文地址:https://www.9cbs.com/read-91280.html

New Post(0)