Request.ServerVariables(“HTTP_REFERER”) 在 IE 中不起作用
Request.ServerVariables("HTTP_REFERER") 在 Internet Explorer 中不起作用。
我们有一个要求,比如有两个不同的网站,www.example1.com 和 www.example2.com。我必须将所有使用 www.example1.com 的用户重定向到 www.example2.com,当我们有意在 www.example2.com 的下拉列表中选择 www.example1.com 时,它应该在没有任何重定向的情况下打开。
为此,我在 www.example1.com 中使用了 Request.ServerVariables("HTTP_REFERER") ,以便我可以根据我应用的重定向来识别谁正在请求 www.example1.com 。这在 Mozilla 和 Google Chrome 等所有标准浏览器中效果很好,但不适用于 Internet Explorer。
我在 www.example1.com 上使用了下面的 ASP 代码,
<%if(Request.ServerVariables("HTTP_REFERER") <> "http://www.example2.org/") then
URL = "http://api.ipinfodb.com/v3/ip-country/?key=c184c2d089c7763a81d7701a662b57fe3bf90dbfd8bf60d29948878531e24472&ip=" & Request.ServerVariables("REMOTE_ADDR")
Set conn = Server.CreateObject("MSXML2.ServerXMLHTTP")
conn.open "GET", URL, False, "", ""
conn.send
UserCountry = conn.ResponseText
conArray = Split(UserCountry, ";")
if ((conArray(3) = "US")) Then
response.redirect("http://www.example2.org/")
end if
end if
%>
它在除 IE 之外的所有浏览器中运行良好。任何人都可以知道这一点吗?请您向我建议所有浏览器(包括 IE)的等效代码,它会给出与上述类似的结果。
The Request.ServerVariables("HTTP_REFERER") is not working in the Internet Explorer.
We have a requirement like, there are two different websites say, www.example1.com and www.example2.com. I have to redirect all the users who uses www.example1.com to www.example2.com, and when we intentionally select www.example1.com in the dropdown list of www.example2.com it should have to open without any redirection.
For this I have used Request.ServerVariables("HTTP_REFERER") in the www.example1.com so that I can Identify who are requesting www.example1.com based on that I applied redirection. This worked great in All standard browsers like Mozilla and Google Chrome but not applying for Internet Explorer.
I used the below ASP code for www.example1.com
<%if(Request.ServerVariables("HTTP_REFERER") <> "http://www.example2.org/") then
URL = "http://api.ipinfodb.com/v3/ip-country/?key=c184c2d089c7763a81d7701a662b57fe3bf90dbfd8bf60d29948878531e24472&ip=" & Request.ServerVariables("REMOTE_ADDR")
Set conn = Server.CreateObject("MSXML2.ServerXMLHTTP")
conn.open "GET", URL, False, "", ""
conn.send
UserCountry = conn.ResponseText
conArray = Split(UserCountry, ";")
if ((conArray(3) = "US")) Then
response.redirect("http://www.example2.org/")
end if
end if
%>
It worked fine in all Browsers except IE. Can any one know regarding this? would you please suggest me the equivalent code for ALL BROWSERS (Including IE) which would give similar results as mentioned.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能依赖
HTTP_REFERER
的存在:用户代理不需要设置它。尝试使用
HTTP_HOST
代替:自 HTTP 1.1 起,主机标头是必需的。You can't rely on
HTTP_REFERER
being present: user agents aren't required to set it.Try using
HTTP_HOST
instead: the host header is mandatory since HTTP 1.1.请检查下面的链接,其中显示 HTTP_REFERER 不是 HTTP 规范的强制成员。
您可以使用服务器变量 SERVER_NAME 来满足您的要求,它应该可以工作。
快乐编码!
Please check below link which says HTTP_REFERER is not a mandatory member of the HTTP specification.
You can use server variable SERVER_NAME for your requirement and it should work.
Happy coding !!