下面是2个例子,用于说明缓存兼容性应用的设计原则:
对于一个需要服务器名的地址的asp应用:不要直接引用http_host/server_name,判断一下是否有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 //对于一个需要记录客户端ip的php应用:不要直接引用remote_addr,而是要使用http_x_forwarded_for, function getuserip (){ $user_ip = $_server["remote_addr"]; if ($_server["http_x_forwarded_for"]) { $user_ip = $_server["http_x_forwarded_for"]; } }
注意:http_x_forwarded_for如果经过了多个中间代理服务器,有何能是逗号分割的多个地址,比如:
200.28.7.155,200.10.225.77 unknown,219.101.137.3
因此在很多旧的数据库设计中(比如bbs)往往用来记录客户端地址的字段被设置成20个字节就显得过小了。
经常见到类似以下的错误信息:
microsoft jet database engine 错误 80040e57
字段太小而不能接受所要添加的数据的数量。试着插入或粘贴较少的数据。
/inc/char.asp,行236
原因就是在设计客户端访问地址时,相关用户ip字段大小最好要设计到50个字节以上,当然经过3层以上代理的几率也非常小。
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




