Web Analytics Made Easy -
StatCounter response.redirect script - CodingForum

Announcement

Collapse
No announcement yet.

response.redirect script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • response.redirect script

    i know this maybe a silly question but how do i insert a redirect script? I have an access database with the following tables: username, Password, UserID. I would like on succesful login, to be able to redirect to a website. Please adjust/ammend this script to show the redirect example. Thanks

    <%@ Language = "VBScript" %>
    <%
    Option Explicit


    Dim cnnLogin
    Dim rstLogin
    Dim strUsername, strPassword
    Dim strSQL

    %>
    <html>
    <head><title>Login Page</title>
    </head>

    <%
    If Request.Form("action") <> "validate_login" Then
    %>
    <form action="checklogin.asp" method="post">
    <input type="hidden" name="action" value="validate_login" />
    <table border="0">
    <tr>
    <td align="right">Login:</td>
    <td><input type="text" name="login" size="20" /></td>
    </tr>
    <tr>
    <td align="right">Password:</td>
    <td><input type="password" name="password" size="20" /></td>
    </tr>
    <tr>
    <td align="right"></TD>
    <td><input type="submit" VALUE="Login" /></td>
    </tr>
    </table>
    </form>
    <%
    Else
    strSQL = "SELECT * FROM Login " _
    & "WHERE username='" & Replace(Request.Form("login"), "'", "''") & "' " _
    & "AND password='" & Replace(Request.Form("password"), "'", "''") & "';"

    Set cnnLogin = Server.CreateObject("ADODB.Connection")
    cnnLogin.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
    & "DBQ=" & Server.MapPath("loginscreen.mdb"))

    et rstLogin = cnnLogin.Execute(strSQL)

    If Not rstLogin.EOF Then

    Else
    %>
    <p>
    <font size="4" face="arial,helvetica"><strong>
    Login Failed - Please verify username and password.
    </strong></font>
    </p>
    <p>
    <a href="login_db.asp">Try Again</a>
    </p>
    <%
    'Response.End
    End If

    ' Clean Up
    rstLogin.Close
    Set rstLogin = Nothing
    cnnLogin.Close
    Set cnnLogin = Nothing
    End If
    %>
    </body>
    </html>

  • #2
    Are you just looking for syntax?? B/C everything else looks right

    If Not rstLogin.EOF Then

    response.redirect("http://www.codingforum.net")

    Else
    %>
    <p>
    <font size="4" face="arial,helvetica"><strong>
    Login Failed - Please verify username and password.
    </strong></font>
    </p>
    <p>
    <a href="login_db.asp">Try Again</a>
    </p>
    <%
    'Response.End
    End If
    I would rather be a lion for a day than a lamb that lives forever.

    Comment


    • #3
      thanks it worked

      Comment


      • #4
        one thing though do your clean up before you redirect otherwise the objects will remain in memory.

        Comment


        • #5
          i never taught about it. how do i clean up? thanks

          Comment


          • #6
            you do the cleanup and then the redirect just like you did at the end. It is just that the way you had it, your code never gets that far.

            If Not rstLogin.EOF Then

            'the user is found so Close and release connections
            'then redirect the user
            rstLogin.Close
            Set rstLogin = Nothing
            cnnLogin.Close
            Set cnnLogin = Nothing

            Response.Redirect "http://www.codingforum.net/"

            Else
            %>
            <p>
            <font size="4" face="arial,helvetica"><strong>
            Login Failed - Please verify username and password.
            </strong></font>
            </p>
            <p>
            <a href="login_db.asp">Try Again</a>
            </p>
            <%
            'Response.End
            End If

            ' Clean Up
            rstLogin.Close
            Set rstLogin = Nothing
            cnnLogin.Close
            Set cnnLogin = Nothing
            End If
            %>
            </body>
            </html>

            Comment

            Working...
            X