ASP如何获取登录的用户名

sunhonglei2004 2008-11-22 09:31:18
我有一个ASP登录页面,login.asp
登录进去之后在index.asp里只显示每个用户名自己的信息

我想问的是:比如我用123登录,如何获取这个用户名,然后在index.asp这个页中只显示123的信息,而不显示其它用户的信息呢,
我想用这条语句,select * from tb where user='123',我怎么样取到这个123呢,


不知道我表达的是否清楚。谢谢
...全文
711 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangxiaoning868 2008-11-22
  • 打赏
  • 举报
回复
参照8楼的写就可以了。8楼的不用session
若用session则登陆成功后,创建一个session("username"),让session("username")request.form("userid")
那查询语句为 sql="select * from logs where user='"&session("username")'"
这么用就行了
sy_binbin 2008-11-22
  • 打赏
  • 举报
回复
sql="select * from logs where user='"&Session("userID")&"'
virgo2008 2008-11-22
  • 打赏
  • 举报
回复
sql="select * from logs where user="&Session("userID")
sunhonglei2004 2008-11-22
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 sy_binbin 的回复:]
你看我8楼的代码了吗
[/Quote]

可是我在index.asp这个页面当中却查询不到相应的信息啊,

比如说我的用户名是123,那传递到index.asp这个页面中应该是
select * from logs where user=123
我现在搞不明白的就是这个where 条件user=123如何用<%=session("userID")%>来表示
sy_binbin 2008-11-22
  • 打赏
  • 举报
回复
你看我8楼的代码了吗
sunhonglei2004 2008-11-22
  • 打赏
  • 举报
回复
我这用session取不到值

login_check.asp代码如下:

<!--#include file="conn.asp"-->
<%
dim userid,pwdid
userid=request.form("userid")
pwdid=request.form("pwdid")
session("userID") = userid '把用户名保存在session中
if userid="" then
response.write "<script>alert('用户名不能为空');history.back();</script>"
end if
if pwdid="" then
response.write "<script>alert('密码不能为空');history.back();</script>"
end if
%>
<%
set rs=server.createobject("adodb.recordset")
sql="select * from tb_user where user_id='"&userid&"' and pwdid='"&pwdid&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write "<script>alert('用户名或密码错误,请重新登录!');history.back();</script>"
response.end
else
if rs("pwdid")<>pwdid then
response.write "<script>alert('用户名或密码错误,请重新登录!');history.back();</script>"
response.end
end if

if userid="admin" then
response.write"<script>location.href='index.asp'</script>"
else
response.write"<script>location.href='index1.asp'</script>"
end if
end if
%>

那个SESSION语句应该写哪到啊,谢谢


virgo2008 2008-11-22
  • 打赏
  • 举报
回复
登陆页面总要输入用户名和密码吧,那你后面的判断就用session("username")=request.form("username")
tomscat 2008-11-22
  • 打赏
  • 举报
回复
s2Sql="select * from tb_logs where user= '" & session("userID") & "'"
sunhonglei2004 2008-11-22
  • 打赏
  • 举报
回复
<%
s2Sql="select * from tb_logs"
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
%>

大侠,这是我index.asp里边的那条查询语句,我应该把<%=session("userID")%>加到哪,

s2Sql="select * from tb_logs where user=????"
sy_binbin 2008-11-22
  • 打赏
  • 举报
回复
<%=session("userID")%>
sunhonglei2004 2008-11-22
  • 打赏
  • 举报
回复
试了好几次,都不行啊,

在index.asp页面里输出
session("userID") 就可以

这个如何在index.asp页面里输出啊,
sy_binbin 2008-11-22
  • 打赏
  • 举报
回复
<%
dim userid,pwdid
userid=request.form("userid")
pwdid=request.form("pwdid")
if userid="" then
response.write " <script>alert('用户名不能为空');history.back(); </script>"
end if
if pwdid="" then
response.write " <script>alert('密码不能为空');history.back(); </script>"
end if
%>
<%
set rs=server.createobject("adodb.recordset")
sql="select * from tb_user where user_id='"&userid&"' and pwdid='"&pwdid&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write " <script>alert('用户名或密码错误,请重新登录!');history.back(); </script>"
response.end
else
if rs("pwdid") <>pwdid then
response.write " <script>alert('用户名或密码错误,请重新登录!');history.back(); </script>"
response.end
else
session("userID") = userid'把用户名保存在session中
response.write" <script>location.href='index.asp' </script>"
end if
end if
%>

在index.asp页面里输出
session("userID") 就可以
sunhonglei2004 2008-11-22
  • 打赏
  • 举报
回复
to sy_binbin

小弟是个菜鸟,能否再说的详细一些,我的login_check.asp代码如下:
<!--#include file="conn.asp"-->
<%
dim userid,pwdid
userid=request.form("userid")
pwdid=request.form("pwdid")
if userid="" then
response.write "<script>alert('用户名不能为空');history.back();</script>"
end if
if pwdid="" then
response.write "<script>alert('密码不能为空');history.back();</script>"
end if
%>
<%
set rs=server.createobject("adodb.recordset")
sql="select * from tb_user where user_id='"&userid&"' and pwdid='"&pwdid&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write "<script>alert('用户名或密码错误,请重新登录!');history.back();</script>"
response.end
else
if rs("pwdid")<>pwdid then
response.write "<script>alert('用户名或密码错误,请重新登录!');history.back();</script>"
response.end
end if

response.write"<script>location.href='index.asp'</script>"
end if
%>

index.asp代码如下:

<%
s2Sql="select * from tb_logs "
set rs=server.CreateObject("ADODB.Recordset")
rs.open s2Sql,conn,1,1
%>

大侠所说的那两句代码应该加在哪个页面中啊,万分感谢,一直在线等待
sy_binbin 2008-11-22
  • 打赏
  • 举报
回复
你在登录成功后用SESSION保存用户名

session("userName") = request("userName")

在页面上直接
<%=session("userName")%>就可以了
cnchart 2008-11-22
  • 打赏
  • 举报
回复
conn database....

set rs=server.createobject("adodb.recordset")
sql="select * from tb where user='123' and rownum=1"
rs.open sql,conn,1,1
if not (rs.eof and rs.bof) then
response.write rs("user")
......
end if
sunhonglei2004 2008-11-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wujl1981 的回复:]
用session
[/Quote]

大侠,能否说的再详细一些呢。
sunhonglei2004 2008-11-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wujl1981 的回复:]
用session
[/Quote]

大侠,能否说的再详细一些呢。
wujl1981 2008-11-22
  • 打赏
  • 举报
回复
用session
XCoder_Studio 2008-11-22
  • 打赏
  • 举报
回复
似乎是正确的,这个需要实践的~
用RecordSet记录集存储信息啊~然后读取记录集的信息就可以了吧

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧