有些页面是需要登录才能打开,如何实现?

我做了一个登录注册的程序,有些页面是需要登录才能打开,但我在地址栏输入相应的网址还是可以正常打开,有什么办法解决啊,同时在登录时也一样,我把URL和传递宾参数拷下来,在地址栏一样可以打开,如何防止这种情况!也就是不能在地址栏直接输入网址进入!
---------------------------------------------------------------

把登陆信息写在cookies或session中,每个页面都校验cookies或session,看看是否已经登陆,没有就不允许访问
---------------------------------------------------------------

if session("aaa")="" then
response.redirect "login.asp"
response.end
end if
加在页首,不登陆就转到login.asp页面

---------------------------------------------------------------

那是因为你的其他页面并没有进行身份验证,也就是说你的登陆只在登录页面有效
---------------------------------------------------------------


---------------------------------------------------------------

login.asp

1 username=request("login")   
2if username="" then   
3response.end   
4end if   
5set rs=server.createobject("adodb.recordset")   
6sql="select * from admin where username='"&username&"'"   
7rs.open sql,conn,1,1   
8if rs.eof and rs.bof then   
9response.write"

<script language="JavaScript">alert('对不起,该用户名不存在或已被删除! \n 请重新输入');"
response.write"javascript:window.location = 'login.asp';</script>

1"   
2response.end   
3end if   
4session("sign")=username   
5rs.close   
6set rs=nothing   
7conn.close   
8set conn=nothing   
9response.Redirect "index.asp"   

check.asp

1   
2if session("sign")="" or session("sign")="anonymous" then   
3response.write "对不起,操作超时,为确保系统安全,请

<a href="login.asp">重新进入</a>

1!"   
2response.end   
3end if   

以后需要验证的页加

---------------------------------------------------------------

只要你在每一页的开头加上

1   
2if session("aaa")="" then   
3response.redirect "login.asp"   
4end if   

---------------------------------------------------------------

在IIS的所要加密的目录,设置匿名登陆用户。一些黄色网站用的就是这方法。

好处有:就算你知道图片的地址,你也下载不了。
---------------------------------------------------------------

比如,在你的登录成功验证后的页面或代码之后,记着要在验证登录成功后:
if username="" or userpass="" then
Response.Cookies("username")=username
Response.Cookies("userpass")=userpass
end if

然后在其它需要保护的页面开头:

1   
2if Request.Cookies("username")="" or Request.Cookies("userpass")="" then   
3response.redirect "login.asp"   
4'或者response.redirect "出错页.asp"   
5end if   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus