注册 登录
编程论坛 ASP技术论坛

用session保存用户的方法--有问题

暂时初学者 发布于 2008-11-13 15:57, 1997 次点击
建了个redirect.asp内容是
<%
if Session("username")<>"" then
response.redirect("main.asp")
end if
%>
然后在index.asp的开头放<!--#include file="redirect.asp"-->


在check.asp里验证成功的条件后面加Session("username")=uname
但是MS没用。谁可以帮我找下原因不。
要是不是这样写的话,应该是怎么写的。谢谢了!
13 回复
#2
hmhz2008-11-13 16:01
MS 是什么?
#3
暂时初学者2008-11-13 16:03
MS=貌似....呵呵
#4
hmhz2008-11-13 16:04
什么叫没用?你是说Session("username")=uname没有把名字保存到Session("username")里去?
#5
暂时初学者2008-11-13 16:08
嗯,是这样的。输入用户名之后,进入check页面。然后就转不到main页面了。把session注释掉又正常了
#6
暂时初学者2008-11-13 16:12
版主,这代码有错吗?
#7
hmhz2008-11-13 16:13
check 页面代码发出来看看
#8
暂时初学者2008-11-13 16:15
<!--#include file="conn_db.asp"-->

<%




uname=trim(Request.Form("name"))
upassword=trim(Request.Form("password"))



set rs=Server.CreateObject("Adodb.Recordset")
sql="select * from [login] where uname='"&uname&"' and upassword='"&upassword&"' "
rs.open sql,conn,1,1
if rs.recordcount=0 then
response.write("<script>alert('数据库中没有这个用户,或者用户名或密码有误!');history.back

();</script>")
else
Session["username"]=uname
response.write("<script>alert('恭喜您,登录成功!

~~');location.href='sdbbsindex.asp';</script>")
end if
rs.close
set rs=nothing


%>
#9
yms1232008-11-13 16:40
Session["username"]=uname
这里错了
在ASP里存储Session不用中括号
Session("username")=uname
#10
暂时初学者2008-11-13 16:43
我是用用()没用,才试了用[]的..还是一样。
#11
yms1232008-11-13 16:46
<!--#include file="conn_db.asp"-->

<%

Session.timeout=30'这里强制Session的过期时间为30分钟。


uname=trim(Request.Form("name"))
upassword=trim(Request.Form("password"))



set rs=Server.CreateObject("Adodb.Recordset")
sql="select * from [login] where uname='"&uname&"' and upassword='"&upassword&"' "
rs.open sql,conn,1,1
if rs.recordcount=0 then
response.write("<script>alert('数据库中没有这个用户,或者用户名或密码有误!');history.back

();</script>")
else
Session["username"]=uname
response.write("<script>alert('恭喜您,登录成功!

~~');location.href='sdbbsindex.asp';</script>")
end if
rs.close
set rs=nothing


%>
#12
暂时初学者2008-11-13 16:47
在check页面...动不了...状态栏显示的是"等待192.168.1.3/main.asp"
跳转不到main.asp
192.168.1.3是本机ip
#13
暂时初学者2008-11-13 16:49
redirect.asp的代码

<%
if Session("username")<>"" then
response.redirect("main.asp")
end if
%>
#14
yms1232008-11-13 19:37
那就不简单是Session问题了,main.asp可能有问题
1