Cache compatibility design for Web applications

Source: Internet
Author: User
Tags servervariables client
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



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.