Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: if Request ==""

  1. #1
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if Request ==""

    I'm making a simple login page, and the first time the user enters I thought I would check it like so:

    Code:
    <%
      if(Request.Form("Password")=="") {
    %>
    
    ......<blah>loging page...
    
    <%
    }
    else {
    ........
    ...check username and password...
    Response.Redirect(...)
    ...
    }
    %>
    But this doesn't seem to work. The if statement fails everytime when I enter from another page.

    Am I doing this all wrong?
    <JPM />

  • #2
    Regular Coder
    Join Date
    Jul 2004
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this
    Code:
    <%
    ' Check to see if the user is logged in
    
    if pageView="login" THEN
    ' Nothing 
    ELSE
    
    if (Request.Cookies("loggedIn")="") OR (Request.Cookies("loggedIn")<>"xY1zZoPQ") THEN
    %>
    
    YOUR LOG IN PAGE
    <%
    ELSE
    %>
    
    <%if pageView="" THEN
    
    ' The User is logged in with permission
    %>
    
    PAGE CONTENTS
    
    <%ELSE%>
    
    NO PAGE CONTENTS
    
    <%END IF%>
    <%END IF%>
    
    <%
    END IF
    IF pageView="login" THEN
    
    ' Log the user into the system
    
    Dim userNameVariable, PasswordVariable
    
    userNameVariable="USERNAME"
    PasswordVariable="PASSWORD"
    
    ' Check details
    
    IF (Request.Form("username")=userNameVariable) AND (Request.Form("pword")=PasswordVariable) THEN
    
    ' They have entered the correct username so we can log them on
    
    Response.Cookies("loggedIn")="xY1zZoPQ"
    
    Response.Redirect("yourpage.asp?=")
    
    ELSE
    %>
    
    <html>
    <head>
    <title>Log In Error!</title>
    </head>
    <body>
    <br>
    <br><BR>
    
    The Username and/or password you have entered is incorrect
    
    <%
    END IF
    %>
    <%END IF%>
    </body>
    </html>
    <%IF pageView="LogOut" THEN
    
    ' Log the user out of the system
    
    Response.Cookies("loggedIn")=""
    Response.Redirect("yourpage.asp")
    END IF
    %>
    Web and Business Development from Cornwall - Startbar.co.uk

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    no, try something more like this:

    <%
    If request("user")="demo" and request("pass")="demo" then
    response.write ("Logged In")
    Else
    response.redirect ("SomeLoginPage.asp?login=err")
    End If
    %>

  • #4
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Startbar, you made an easy script into something complicated.
    Angst, you need to be a little bit more exact.

    Also, there is a problem with your code JPM. You are using { and }. ASP does not use that nor uses ==.

    Let's actually create an ASP page that we can test, to see if there is a problem with JPM's web server, or if it was just his code.

    JPM, the way you are writing your form is simple to do, try this code, and tell me if it works.

    login.asp
    Code:
    <%
    Dim password
    Dim username
    
    username = Request.Form("username")
    password = Request.Form("password")
    
    If Request.Form("password") = "" Then
    %>
    <form method="post" action="login.asp">
    <table border="1">
      <tr>
        <td><b>User Name:</b></td>
        <td><input type="text" size="20" maxlength="16" name="username"></td>
      </tr>
      <tr>
        <td><b>Password:</b></td>
        <td><input type="password" size="20" maxlength="16" name="password"></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><input type="submit" value=" Submit "></td>
      </tr>
    </table>
    </form>
    <%
    Else
      If username = "myusername" And password = "mypassword" Then
        Response.Redirect("loggedin.asp")
      Else
        Response.Write "<i>The username and/or password are incorrect.</i>"
      End If
    End If
    %>
    I hope this explains a few things about ASP you might not have known.
    Feel free to ask some questions.

  • #5
    Regular Coder
    Join Date
    Jul 2004
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry.. just trying to be helpful ..
    Web and Business Development from Cornwall - Startbar.co.uk

  • #6
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by startbar
    sorry.. just trying to be helpful ..
    That's ok man, you're script looks like it would work, but I wouldn't use cookies for loging in, unless you needed to be sent to a page by redirect, and couldn't post the data over to the next page.
    To keep the user logged in is when I would use cookies.

  • #7
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,071
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Actually JPM's code is in JScript and yes ASP does support JScript so the syntax is correct.

    JPM are you using this at the very top of your page to tell ASP that the code is in Jscript and not VBScript?
    <%@ Language=JScript %>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •