web| Cache | design
After the agent, because the client and the service increased between the middle tier, so the server can not directly to the client IP, server-side applications can not directly by forwarding the requested address to return to the client. However, in the HTTD header information of the forwarding request, the http_x_forwarded_ is added???? Information. The server address used to track the original client IP address and the original client request:
Here are 2 examples that illustrate the design principles for caching compatibility applications:
' For an ASP application that requires a server name: Do not refer directly to Http_host/server_name to determine if there is a http_x_forwarded_server
function GetHostName ()
Dim hostName As String = ""
HostName = Request.ServerVariables ("Http_host")
If not IsDBNull (Request.ServerVariables ("Http_x_forwarded_host")) Then
If Len (Trim (Request.ServerVariables ("Http_x_forwarded_host")) > 0 Then
HostName = Request.ServerVariables ("Http_x_forwarded_host")
End If
End If
Return Hostnmae
End Function
For a PHP application that needs to record client IP: Do not refer directly to REMOTE_ADDR, but to use http_x_forwarded_for,
function Getuserip () {
$user _ip = $_server["REMOTE_ADDR"];
if ($_server["Http_x_forwarded_for"]) {
$user _ip = $_server["Http_x_forwarded_for"];
}
}
Note: If http_x_forwarded_for passes through multiple intermediate proxy servers, what can be a comma-separated number of addresses,
For example: 200.28.7.155,200.10.225.77 unknown,219.101.137.3
Therefore, in many old database design (such as BBS) is often used to record the client address of the field is set to 20 bytes is too small.
You often see error messages that are similar to the following:
The Microsoft JET Database Engine error ' 80040e57 ' field is too small to accept the number of data to be added. Try inserting or pasting less data.
/inc/char.asp, line 236
The reason is that when designing a client access address, the relevant User IP field size is best designed to more than 50 bytes, of course, through the 3-tier agent is also very small probability