ASP中如何使用session?
用户登陆系统后,系统如何运用session将一个会话期间用户进行的操作活动记录在里面,如果用户未登陆或会话期间超时会给予提示?请问下面的代码和session有关吗?<%'...
用户登陆系统后,系统如何运用session将一个会话期间用户进行的操作活动记录在里面,如果用户未登陆或会话期间超时会给予提示?
请问下面的代码和session有关吗?
<%
'-----------------------------------------
oabusyname=request.cookies("oabusyname")
oabusyusername=request.cookies("oabusyusername")
oabusyuserdept=request.cookies("oabusyuserdept")
oabusyuserlevel=request.cookies("oabusyuserlevel")
if oabusyusername="" then response.redirect "default.asp"
'--------------------------------------
'打开数据库,读出编辑通讯录权限
set conn=opendb("oabusy","conn","accessdsn")
set rs=server.createobject("adodb.recordset")
sql="select * from userinf where username=" & sqlstr(oabusyusername)
rs.open sql,conn,1
allow_edit_person_personinf=rs("allow_edit_person_personinf")
%> 展开
请问下面的代码和session有关吗?
<%
'-----------------------------------------
oabusyname=request.cookies("oabusyname")
oabusyusername=request.cookies("oabusyusername")
oabusyuserdept=request.cookies("oabusyuserdept")
oabusyuserlevel=request.cookies("oabusyuserlevel")
if oabusyusername="" then response.redirect "default.asp"
'--------------------------------------
'打开数据库,读出编辑通讯录权限
set conn=opendb("oabusy","conn","accessdsn")
set rs=server.createobject("adodb.recordset")
sql="select * from userinf where username=" & sqlstr(oabusyusername)
rs.open sql,conn,1
allow_edit_person_personinf=rs("allow_edit_person_personinf")
%> 展开
1个回答
展开全部
简单容学的ASP教程类电子书下载
http://www.gy16.com/gy/sort/e_77_2.htm
session应用:用户登陆
user=replace(trim(request("username")),"'","")
password=replace(trim(request("password")),"'","")
set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from [user] where password='"&password&"' and user='"&user&"' " ,conn,1,1
if not(rs.bof and rs.eof) then
'如果不是为空,则执行
if password=rs("password") and user=rs("user") then
'如果password=rs("password") and user=rs("user") ,则执行
session("adminlogin")="ok"
,则将session("adminlogin")赋一个值为"ok"
session.Timeout=600
,设置超时600秒
else
response.write "<script LANGUAGE='javascript'>alert('对不起,登录失败!');history.go(-1);</script>"
end if
else
response.write "<script LANGUAGE='javascript'>alert('对不起,登录失败!');history.go(-1);</script>"
end if
session应用:用户后进入的页面
<%
if session("adminlogin") <> "ok" then
'session("adminlogin") 不为ok则执行下面语句
%>
<SCRIPT LANGUAGE=vbscript>
<!--
msgbox("对不起,您还没有登录!")
window.top.location.href="../login.htm"
-->
</SCRIPT>
<%
end if
%>
session应用:用户退出
session("adminlogin")=""
,将session("adminlogin")设置为空
session.abandon()
'退出登陆时尽量用清空的方法,而不要用Session.Abandon这删除的方法
'如:session("userid") = ""
'直接将session("userid")变量置空即可`~`
response.write "<script language=""javascript"">" & VbCrLf
response.write " window.top.location.href=""../../index.asp"";" & VbCrLf
response.write "</script>" & VbCrLf
参考资料:http://www.at63.com
http://www.gy16.com/gy/sort/e_77_2.htm
session应用:用户登陆
user=replace(trim(request("username")),"'","")
password=replace(trim(request("password")),"'","")
set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from [user] where password='"&password&"' and user='"&user&"' " ,conn,1,1
if not(rs.bof and rs.eof) then
'如果不是为空,则执行
if password=rs("password") and user=rs("user") then
'如果password=rs("password") and user=rs("user") ,则执行
session("adminlogin")="ok"
,则将session("adminlogin")赋一个值为"ok"
session.Timeout=600
,设置超时600秒
else
response.write "<script LANGUAGE='javascript'>alert('对不起,登录失败!');history.go(-1);</script>"
end if
else
response.write "<script LANGUAGE='javascript'>alert('对不起,登录失败!');history.go(-1);</script>"
end if
session应用:用户后进入的页面
<%
if session("adminlogin") <> "ok" then
'session("adminlogin") 不为ok则执行下面语句
%>
<SCRIPT LANGUAGE=vbscript>
<!--
msgbox("对不起,您还没有登录!")
window.top.location.href="../login.htm"
-->
</SCRIPT>
<%
end if
%>
session应用:用户退出
session("adminlogin")=""
,将session("adminlogin")设置为空
session.abandon()
'退出登陆时尽量用清空的方法,而不要用Session.Abandon这删除的方法
'如:session("userid") = ""
'直接将session("userid")变量置空即可`~`
response.write "<script language=""javascript"">" & VbCrLf
response.write " window.top.location.href=""../../index.asp"";" & VbCrLf
response.write "</script>" & VbCrLf
参考资料:http://www.at63.com
参考资料: http://www.baidu.com/s?wd=ASP%D6%D0%C8%E7%BA%CE%CA%B9%D3%C3session&cl=3
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询