asp中如何防止session丢失,并且session设置保存时间
我的登录检测页面checklg.asp代码是:<%DimCfg,Flib,DbSetCfg=NewConfigSetFlib=NewFunctionLibSetDb=Ne...
我的登录检测页面checklg.asp代码是:
<%
Dim Cfg,Flib,Db
Set Cfg = New Config
Set Flib = New FunctionLib
Set Db = New DBControl
Dim UserName,Password,CodeID,CodeIDChecked,Pwd
Dim Sql,Rs
UserName = Trim(Request.Form("UserName"))
Password = Trim(Request.Form("Password"))
Pwd = Md5(Cfg.Password_EncodeKey & MD5(Password))
If UserName = "" Then
Flib.Alert "用户名不能放空!","BACK",0
Response.End
End If
If Password = "" Then
Flib.Alert "密码不能放空!","BACK",0
Response.End
End If
Sql = "select top 1 Power,Pwd from Power where Power='"& UserName &"'"
Db.Open()
Set Rs = Db.ExeCute2(Sql)
If Rs.Eof and Rs.Bof Then
Rs.Close
Set Rs = Nothing
Db.Close
Flib.Alert "该用户不存在!","BACK",0
Response.End
End If
Rs.Close
Sql = "select top 1 Power,Pwd from [Power] where Power='"& UserName &"' and Pwd='"& Pwd &"'"
Db.Open()
Set Rs = Db.ExeCute2(Sql)
If Rs.Eof and Rs.Bof Then
Rs.Close
Set Rs = Nothing
Db.Close
Flib.Alert "密码错误!","BACK",0
Response.End
End If
Rs.Close
Set Rs = Nothing
Db.Close
Session("Flag1") = "Logined"
Session("Power") = "UserName"
Response.Cookies("Power")=userName
Response.Redirect("../main.htm")
%>
我在最后面添加了记录session,
后台检测是否已登录页check.asp代码:
<%
if trim(request.cookies("userinfor")("Power"))<>"" then
session("Power")=request.cookies("userinfor")("Power")
end if
if trim(session("Power"))="" then
response.write "<script language=’javascript’>alert(’对不起,您还没有登录!’);location='../default.asp';</script>"
end if
%>
我在登陆后,直接在地址栏内输入要访问的后台地址,总提示:“对不起,您还没有登录!” ,这是什么原因呀?
请高手帮忙解答一下,这个问题该如何解决,防止session丢失,并且session设置保存时间已!谢谢高手
上面的check.asp是我修改后的:
这是我修改调试时出现问题的check.asp:
<%
if Session("Power") = "" then
Session("Power")=Request.Cookies("power")
response.write "<script>alert('对不起,您还没有登录!');location='../default.asp'</script>"
end if
%>
一楼的大哥,什么意思呀??什么问题? 不太明白您的意思,请明示! 展开
<%
Dim Cfg,Flib,Db
Set Cfg = New Config
Set Flib = New FunctionLib
Set Db = New DBControl
Dim UserName,Password,CodeID,CodeIDChecked,Pwd
Dim Sql,Rs
UserName = Trim(Request.Form("UserName"))
Password = Trim(Request.Form("Password"))
Pwd = Md5(Cfg.Password_EncodeKey & MD5(Password))
If UserName = "" Then
Flib.Alert "用户名不能放空!","BACK",0
Response.End
End If
If Password = "" Then
Flib.Alert "密码不能放空!","BACK",0
Response.End
End If
Sql = "select top 1 Power,Pwd from Power where Power='"& UserName &"'"
Db.Open()
Set Rs = Db.ExeCute2(Sql)
If Rs.Eof and Rs.Bof Then
Rs.Close
Set Rs = Nothing
Db.Close
Flib.Alert "该用户不存在!","BACK",0
Response.End
End If
Rs.Close
Sql = "select top 1 Power,Pwd from [Power] where Power='"& UserName &"' and Pwd='"& Pwd &"'"
Db.Open()
Set Rs = Db.ExeCute2(Sql)
If Rs.Eof and Rs.Bof Then
Rs.Close
Set Rs = Nothing
Db.Close
Flib.Alert "密码错误!","BACK",0
Response.End
End If
Rs.Close
Set Rs = Nothing
Db.Close
Session("Flag1") = "Logined"
Session("Power") = "UserName"
Response.Cookies("Power")=userName
Response.Redirect("../main.htm")
%>
我在最后面添加了记录session,
后台检测是否已登录页check.asp代码:
<%
if trim(request.cookies("userinfor")("Power"))<>"" then
session("Power")=request.cookies("userinfor")("Power")
end if
if trim(session("Power"))="" then
response.write "<script language=’javascript’>alert(’对不起,您还没有登录!’);location='../default.asp';</script>"
end if
%>
我在登陆后,直接在地址栏内输入要访问的后台地址,总提示:“对不起,您还没有登录!” ,这是什么原因呀?
请高手帮忙解答一下,这个问题该如何解决,防止session丢失,并且session设置保存时间已!谢谢高手
上面的check.asp是我修改后的:
这是我修改调试时出现问题的check.asp:
<%
if Session("Power") = "" then
Session("Power")=Request.Cookies("power")
response.write "<script>alert('对不起,您还没有登录!');location='../default.asp'</script>"
end if
%>
一楼的大哥,什么意思呀??什么问题? 不太明白您的意思,请明示! 展开
4个回答
展开全部
给个例子如下:
从登录页面取得用户名和密码
<%
username=Request("username")
password=Request("password")
sql="select id,username,password from admin where username='"&username&"' and password='"&password&"'"
response.Write sql
Set rs=cn.execute(sql)
If Not (rs.bof Or rs.eof) Then
session.Timeout=1000
Session("log_name")=rs("username")
Session("log_role")=rs("class")
Response.Redirect "admin_login1.asp"
Else
Response.Redirect "login.asp?errno=1"
End If
%>
在admin_login1.asp页里,可根据Session("log_role")不同的值跳转不同页面,用于权限不同,显示内容也不一样
<%
If Session("log_role")="9" Then
response.redirect "index.asp"
else if Session("log_role")="6" Then
response.redirect "indexz.asp"
else if Session("log_role")="0" Then
response.redirect "index2.asp"
end if
end if
end if
%>
从登录页面取得用户名和密码
<%
username=Request("username")
password=Request("password")
sql="select id,username,password from admin where username='"&username&"' and password='"&password&"'"
response.Write sql
Set rs=cn.execute(sql)
If Not (rs.bof Or rs.eof) Then
session.Timeout=1000
Session("log_name")=rs("username")
Session("log_role")=rs("class")
Response.Redirect "admin_login1.asp"
Else
Response.Redirect "login.asp?errno=1"
End If
%>
在admin_login1.asp页里,可根据Session("log_role")不同的值跳转不同页面,用于权限不同,显示内容也不一样
<%
If Session("log_role")="9" Then
response.redirect "index.asp"
else if Session("log_role")="6" Then
response.redirect "indexz.asp"
else if Session("log_role")="0" Then
response.redirect "index2.asp"
end if
end if
end if
%>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Session("Flag1") = "Logined"
Session("Power") = "UserName"
Response.Cookies("Power")=userName
这里有没有问题
Session("Power") = "UserName"
Response.Cookies("Power")=userName
这里有没有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
session.TimeOut=9999
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询