| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 956 人关注过本帖
标题:session值传递
只看楼主 加入收藏
whjwruu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-4-6
结帖率:0
收藏
已结贴  问题点数:10 回复次数:3 
session值传递
现有多个页面A页面用于登录。请问如何在A页面中设置session值用于保存用户登录信息。用户名 密码等。并且如何查看该保存了的session值 。其他页面怎么去调用该session值!求达人赐教。。困扰一天了。现付A页面代码。请教怎么修改。
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/conn.asp" -->
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows

Set Recordset1_cmd = Server.CreateObject (")
Recordset1_cmd.ActiveConnection = MM_conn_STRING
Recordset1_ = "SELECT * FROM dbo.student"
Recordset1_cmd.Prepared = true

Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("textfield"))
If MM_valUsername <> "" Then
  Dim MM_fldUserAuthorization
  Dim MM_redirectLoginSuccess
  Dim MM_redirectLoginFailed
  Dim MM_loginSQL
  Dim MM_rsUser
  Dim MM_rsUser_cmd
  
  MM_fldUserAuthorization = ""
  MM_redirectLoginSuccess = "框架.asp"
  MM_redirectLoginFailed = "denglushibai.asp"

  MM_loginSQL = "SELECT stu_name, stu_pwd"
  If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
  MM_loginSQL = MM_loginSQL & " FROM dbo.student WHERE stu_name = ? AND stu_pwd = ?"
  Set MM_rsUser_cmd = Server.CreateObject (")
  MM_rsUser_cmd.ActiveConnection = MM_conn_STRING
  MM_rsUser_ = MM_loginSQL
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 50, MM_valUsername) ' adVarChar
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 50, Request.Form("textfield2")) ' adVarChar
  MM_rsUser_cmd.Prepared = true
  Set MM_rsUser = MM_rsUser_cmd.Execute

  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE3 {
    font-size: 24px;
    font-weight: bold;
    color: #0000CC;
}
.STYLE4 {
    font-size: 18px;
    font-weight: bold;
    color: #00CC99;
}
body{background-image:url(image/09b4cd507fcb0da38c5430f6.jpg);}
.STYLE6 {font-size: 12px}
.STYLE7 {color: #FF0033}
.STYLE8 {font-size: 24px}
.STYLE10 {font-size: 24px; font-weight: bold; }
a:link {
    text-decoration: none;
}
a:visited {
    text-decoration: none;
}
a:hover {
    text-decoration: none;
}
a:active {
    text-decoration: none;
}
#apDiv1 {
    position:absolute;
    left:290px;
    top:456px;
    width:66px;
    height:15px;
    z-index:1;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>

<body>
<table width="100%" border="0">
  <tr>
    <td><div align="center" class="STYLE3">首页 <a href="wodexinxi.asp" target="_blank">我的信息 </a><a href="list.asp" target="_blank">电子作品区</a><a href="教学资源.asp" target="_blank"></a> <a href="教学资源.asp" target="_blank">教学资源区 </a><a href="管理员登录.asp" target="_blank">管理员</a><a href="管理员.asp" target="_blank"></a></div></td>
  </tr>
  <tr>
    <td><div align="center" class="STYLE4">
       <p>&nbsp;</p>
      <marquee behavior="scroll" bgcolor="#FF3300" direction="right" scrollamount="3" scrolldelay="20">欢迎光临本系统!</marquee>
      <p>电子档案管理系统</p>
    </div></td>
  </tr>
  <tr>
    <td><div align="center">             <span class="STYLE6"> <span class="STYLE7"> -记录我的成长记录</span></span></div></td>
  </tr>
</table>
<form ACTION="index.asp" method="POST" name="form1" id="form1" onsubmit="MM_validateForm('textfield','','R','textfield2','','R');MM_validateForm('textfield','','R','textfield2','','R');return document.MM_returnValue">
  <table width="100%" height="671" border="0">
    <tr>
      <td width="50%" height="288" valign="top"><table width="100%" border="0">
        <tr>
          <td width="22%">最新作品</td>
          <td width="49%" onfocus="MM_validateForm('textfield','','R','textfield2','','R');return document.MM_returnValue">推荐作品</td>
          <td width="29%">more&gt;&gt;</td>
        </tr>
      </table>
        <table width="100%" border="0">
          <tr>
            <td width="71%" height="40">111</td>
            <td width="29%">09-1-1</td>
          </tr>
          <tr>
            <td height="45">222</td>
           <td>09-1-2</td>
          </tr>
          <tr>
            <td height="31">333</td>
            <td>09-1-3</td>
          </tr>
          <tr>
            <td height="47">444</td>
            <td>09-1-4</td>
          </tr>
        </table>
        <p>&nbsp;</p>
      <p>&nbsp;</p></td>
      <td width="50%" valign="top"><table width="100%" border="0">
        <tr>
          <td height="24">    电子作品搜索</td>
        </tr>
      </table>
        <table width="100%" border="0">
          <tr>
            <td width="51%" height="78"><label>
              <div align="center">
                <select name="select" id="select">
                  <option>==请选择学科==</option>
                </select>
              </div>
            </label></td>
            <td width="49%">&nbsp;</td>
          </tr>
          <tr>
            <td height="94"><label>
              <div align="center">
                <select name="select2" id="select2">
                  <option>==请选择类型==</option>
                </select>
              </div>
            </label></td>
            <td><label>
              <div align="center">
                <input type="submit" name="button" id="button" value="GO" />
              </div>
            </label></td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td height="377" valign="top"><table width="100%" border="0">
        <tr>
          <td width="22%"><div align="center"><a href="register.asp" target="_parent">学生注册</a></div></td>
          <td width="21%"><div align="center"><a href="zhuce.asp" target="_blank">教师注册</a></div></td>
          <td width="57%"><div align="left"><a href="jiaoshidenglu.asp" target="_blank">登录</a></div></td>
        </tr>
      </table>
      <table width="100%" height="213" border="0">
          <tr>
            <td height="60">用户名:
              <label>
              <input type="text" name="textfield" id="textfield" />
            </label></td>
          </tr>
          <tr>
            <td height="63">密 码:
              <label>
              <input type="password" name="textfield2" id="textfield2" />
            </label></td>
          </tr>
          <tr>
            <td><label>
                    
                  <input type="submit" name="button2" id="button2" value="登录" />
            </label>
              <label>
              <input type="reset" name="button3" id="button3" value="重置" />
            </label></td>
          </tr>
        </table>
        <p>&nbsp;</p>
      <p>&nbsp;</p></td>
      <td valign="top"><table width="100%" border="0">
        <tr>
          <td height="31">会员服务</td>
        </tr>
      </table>
        <table width="100%" border="0">
          <tr>
            <td height="95"><a href="wodexinxi.asp" target="_blank">我的信息>></a></td>
            <td><a href="list.asp" target="_blank">我的作品>></a></td>
          </tr>
          <tr>
            <td height="107">我的档案&gt;&gt;</td>
            <td>我的发言&gt;&gt;</td>
          </tr>
        </table>
      <p>&nbsp;</p></td>
    </tr>
  </table>
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>


在线等。。。。在线等。。在线等。。。
搜索更多相关主题的帖子: session 
2010-06-05 20:13
icecool
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:20
帖 子:1216
专家分:1376
注 册:2005-3-14
收藏
得分:5 
登陆成功时设置一个SESSION,
session("username")=request("textfield")

这样显示出来:response.write session("username")

http://toorup.3v.do
loading...
2010-06-05 21:43
whjwruu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-4-6
收藏
得分:0 
A页面上的session值不需要设置么。仍就是Session("MM_Username") = MM_valUsername吗?我在登录成功页面照你说的设置了session可还是显示不出信息来~B页面代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
登录成功!
<%session("username")=request("textfield")
response.write session("username") %>
</body>

</html>如果要调用session的值请问该如何调用!谢谢
2010-06-06 01:24
上善若水4125
Rank: 1
等 级:新手上路
帖 子:7
专家分:7
注 册:2010-6-7
收藏
得分:5 
   A  页面登陆时,加上一段代码
session("user_name")=request("user_name")

其他页面可以加上一段代码,防止没有登录
if session("user_name") ="" then
Response.Write("<SCRIPT language=JavaScript>alert('请先登录');this.location.href='index.asp';</SCRIPT>")
end if

调用时可以写
user_name=session("user_name")
response.white user_name

菜鸟飘过~~~~~~~
2010-06-07 16:56
快速回复:session值传递
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034999 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved