饼干让我疯狂! ASP - VBScript

时间:2014-05-22 18:48:48

标签: cookies vbscript asp-classic

我尝试使用这些Cookie,因此一旦用户/传递正确,它将启动一个cookie,以便用户在重新登录时始终显示用户名(请记住我的功能)。

虽然这段代码给了" usernameCookie"当我在同一页面检查它时,它没有将值传递给下一页。它已经不再存在了。当然,我使用了buffer = true,但这让我发疯,为什么它不起作用。

<%@ language="VBscript"%>
<% response.buffer = True %>
<!-- #include file = "ddsn.asp" -->
<!-- #include file = "sfuncs.asp" -->

<!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></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>

<!--Initiate form validation - in this example on the login form-->
<script type="text/javascript">
$(document).ready(function() {
    $("#loginform").validate();
});
</script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

<%
msg = ""

If request.form ("password") <> "" Then
    Set rs = Server.CreateObject("ADODB.RecordSet")

    SQL = "Select id,firstName,lastName,username,password,permissions,status FROM dispatchersTBL WHERE username='" & request.form ("username") & "' and password='" & request.form ("password") & "'"

    If inStr(1,SQL,";") or inStr(1,SQL,"''") OR inStr(1,LCase(SQL)," or ") Then msg = "<strong>Wrong Username or Password</strong>" End If

    rs.Open SQL,SQLDSN,3,1

    If NOT rs.EOF Then
        Session("login") = "True"
        Session("loggedUserID") = rs("id")
        Session("fullName") = rs("firstName") & " " & rs("lastName")
        Session("permissions") = rs("permissions")
        status = rs("status")
        Session.Timeout = 1440

        If status = "Inactive" Then
            msg = "<p><strong>Inactive User. Please contact the administrator.</strong></p>"
        Else
            response.cookies("usernameCookie") = rs("username")
            response.cookies("passwordCookie") = rs("password")
            response.cookies("usernameCookie").expires = Date() + 30
            response.cookies("passwordCookie").expires = Date() + 30

            response.redirect adminSiteURL & "co-worker-sms.asp"
        End If
    Else
        msg = "<p><strong>Wrong Username or Password</strong></p>"
    End if
    rs.Close
    Set rs = Nothing
End if
%>

<div id="admin_wrapper">
    <form action="default.asp" id="login" method="post">
        <%=msg%>

        <!-- TEXTBOXES -->
        <label>Username</label><br />
        <input name="username" type="text" value="<%=request.cookies("usernameCookie")%>" class="text large required" id="username" /><br />

        <div class="clearfix">&nbsp;</div>

        <label>Password</label><br />
        <input name="password" type="password" value="<%=request.cookies("passwordCookie")%>" class="text large required" id="password" /><br />

        <div class="clearfix">&nbsp;</div>

        <p><input name="btnLogin" type="submit" class="submit" id="btnLogin" value="LOGIN" /></p>
    </form>
</div>

</body>
</html>

我错过了什么?

1 个答案:

答案 0 :(得分:0)

我还没有看到您的登录页面,但您的代码似乎没问题 - 当您尝试检索时,您确定要执行request.cookies吗?

尝试制作一个这样的简单页面

<%
' put cookie 
Response.Cookies("usernameCookie") = "Superman"
Response.Cookies("usernameCookie").Expires = Date() + 10

Response.Cookies("passwordCookie") = "Batman"
response.Cookies("passwordCookie").Expires = Date() + 10
%>

<% ' Print my cookie %>
<input type="text" value="<% = request.cookies("usernameCookie") %>" name="username">
<br />
<input type="text" value="<% = request.cookies("passwordCookie") %>" name="password">

在重新加载页面后,您的输入字段应该具有“超人”和“蝙蝠侠”