存档

文章标签 ‘http-referer’

在网上下载的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 [...]

十 27th, 2008 | Filed under ASP, Share(分享)