我在第一页上有一个登录表单供用户登录,在登录表单上我有3个文本字段,即电子邮件,密码和代码。当用户输入正确的凭据并输入其代码时,登录将成功。我在第二页上所做的是使用Request.Form(" Code")请求用户输入的代码,我将其分配给第2页的文本字段。但是当你输入正确的文件并使用代码时,我无法在文本字段中收到第2页上的代码。
第1页
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/sample.asp" -->
<%
' *** 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("email"))
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 = "page2.asp"
MM_redirectLoginFailed = "error.asp"
MM_loginSQL = "SELECT email, password"
If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
MM_loginSQL = MM_loginSQL & " FROM dbo.profile WHERE email = ? AND password = ?"
Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
MM_rsUser_cmd.ActiveConnection = MM_viva_web_STRING
MM_rsUser_cmd.CommandText = MM_loginSQL
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 100, MM_valUsername) ' adVarChar
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 100, Request.Form("password")) ' 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.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="shortcut icon" href="../imgs/viva_icon.ico" /><style type="text/css">
.pagefit {
position: relative;
width: 100%;
}
textfields {
}
.textfield {
font-family: Tahoma, Geneva, sans-serif;
font-size: 16px;
color: #030303;
}
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
font-size: 13px;
}
.style1 {
font-size: 24px;
font-weight: bold;
}
</style>
</head>
<body>
<form METHOD="POST" id="form1" name="form1" action="<%=MM_LoginAction%>">
<table width="278" border="1">
<tr>
<td width="67"><p>Email</p></td>
<td width="195"><label for="email"></label>
<input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Password</td>
<td><label for="password"></label>
<input type="text" name="password" id="password" /></td>
</tr>
<tr>
<td>Code</td>
<td><label for="code"></label>
<input type="text" name="code" id="code" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
第2页
<%
Dim req
req = Request.Form("code")
%>
<input name="textfield" type="text" id="textfield2" value="<%=req%>" />
答案 0 :(得分:1)
我熟悉此代码,因为它是Dreamweaver&#34;登录用户&#34;服务器行为。您无法通过&#34; Request.Form&#34;来获取该代码。因为登录不是将登录数据发布到下一页。
使用此代码时会发生什么情况:创建会话"MM_Username"
和"MM_UserAuthorization"
(如果您使用用户级别)。
你可以做什么(我为我的许多网站做了这个),如果通过在设置Session("MM_Username")
之后添加此行,登录有效,它会为你的代码创建一个额外的会话/ p>
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
' Here is your new code session
Session("MM_code") = Request.Form("code")
然后,在下一页上,要检索代码,只需输入:
<%=Session("MM_code")%>
我刚发布之前测试了这个,它可以正常工作。 :)