首页 服务器 编程 必备知识 搜索引擎 圩日手册
站内搜索
最近浏览
推荐文章
热文排行

HTTP-REFERER+Session


在网上下载的CMS虽然是开源,作者也称安全,但是还是有些让人不能放心。今天闲来没事,研究研究给我的程序加一道锁。要做就做万用锁,而且什么CMS都可以使用。用Session来实现,在后台公共引用页面加入判断,如果Session("safe")为空,跳转到admin.asp,代码如下:

< %if session("safe")="" then response.redirect "admin.asp"%>
然后写一个admin.asp,将HTTP-REFERER保存到Session,如果登陆成功释放Session,然后跳转到HTTP-REFERER记录的页面,这样即使知道我们的后台账号,密码,也不能进入我们的后台。

<!--#include file="inc/md5.asp"-->
< %
'定制服务请与我联系
'Design By +飞猫(QQ:77068320;Mail:mqycn@126.com)
if request.querystring="Login_"&date()&"-"&replace(time(),":","-") then
%><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"/><title>安全模式登陆</title><style type="text/css">*{margin:0px;}body{margin:0px;background:#666;text-align:center}h3{background:#BBB}div{border:#CCC solid 10px;margin-left:auto;margin-right:auto;margin-top:200px;width:400px;background:#AAA;line-height:30px;}input{border:2px solid #CCC;background:#EEE;}h5 a{text-decoration:none;color:#000;}h5 a:hover{text-decoration:underline overline;}</style>
</head><div><form action="?LoginIn" method="post"><h3>使用安全模式(Use Safe-Mode)</h3>请输入您的ADMIN_CODE:<br /><input name=AC type=password maxlength=7/>  <input type=submit value="安全ADMIN_CODE"/></form><h5>[<a href="http://www.miaoqiyuan.cn" target="_blank">Design Home</a>][<a href="#">Site Home</a>]</h5></div></html>
< %
        response.end
end if

admin_code="78C94776A5FC6724A047D802B6110F05"
if admin_code=md5(request("AC")) or session("safe_mode")="ok" then
        session("safe_mode")="ok"
        gourl=replace(session("GoUrl"),"%5F","_")
        session.contents.remove("GoUrl")
        if gourl="" then gourl="/"
        response.redirect gourl
else
        if Session("GoUrl")="" then Session("GoUrl")=Request.Servervariables("HTTP_REFERER")
        response.redirect "?Login_"&date()&"-"&replace(time(),":","-")
end if
%>
呵呵,简单吧,测试下吧。
怎么没有反应。试验再三得出结论。Response.redirect直接跳转的,不会产生HTTP-REFERER。又试验了Javascript的Location.href,仍然不能解决问题。难道只有通过A点击才能获取吗?正要在判断页面加入Session来保存登陆页面的地址,忽然想起了FORM,它也可以获取到HTTP-REFERER。
这样简单了,用Javascript模拟FORM提价,代码如下:

< %if session("safe_mode")<>"ok" then response.write "<form action=""../../admin.asp"" method=""post"" id=""a""><script type=""text/javascript"">document.getElementById(""a"").submit();</script>":response.end%>
</form>
OK,问题解决

我有测试了几种方式,发现了HTTP-REFERER的工作方式如下:
下列情况是从浏览器的地址栏正常取得Request.ServerVariables("HTTP_REFERER")的:
1.直接用<a href>
2.用Submit或<input type=image/>提交的表单(POST or GET)
3.使用Jscript提交的表单(POST or GET)

下面我们再看看Request.ServerVariables("HTTP_REFERER")不能正常取值的情况:
1.从收藏夹链接
2.单击'主页'或者自定义的地址
3.利用Jscript的location.href or location.replace()
4.在浏览器直接输入地址
5.< %Response.Redirect%>
6.< %Response.AddHeader%>或<meta http-equiv=refresh>转向
7.用XML加载地址

显然,Request.ServerVariables("HTTP_REFERER")在多数情况下是不能正常工作的,下面我们看一个例子:
ref.asp
< %
response.write “You came from: " & request.servervariables("http_referer")
%>

ref.htm
< %
Response.AddHeader “Refresh", “10;URL=ref.asp"
%>

</meta><meta http-equiv='refresh' content='10;URL=ref.asp'>

<form method=GET action=ref.asp name=getform>
<input type=submit value=' Go there (GET) />> ‘>
<input type=image style='cursor:hand'/>
</form><p>
看看上面的代码会得到什么的结果.
<form method=POST action=ref.asp name=postform>
<input type=submit value=' Go there (POST) />> ‘>
<input type=image style='cursor:hand'/>
</form></p><p>

<a href='ref.asp'>直接链接<p>

<a href='#' onclick='window.location.href="ref.asp";return false;'>javascript location</a>

<a href='#'onclick='window.location.replace("ref.asp");return false;'>javascript replace</a>

<a href='#' onclick='document.getform.submit();return false;'>javascript GET</a>

<a href='#' onclick='document.postform.submit();return false;'>javascript POST </a> </p></a></p></meta></a>

[wangjy17908]
添加时间:2009-09-16
版权所有(C)2005-2015