Stupid question about passing variables

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

    #1

    Stupid question about passing variables

    Sorry for the stupid question but I cannot see what I am doing wrong. I found this code to password protect our ASP pages and it works fine but I am trying to pass a variable between pages so I get re-directed to the page I want. I just cannot figure out what I am doing wrong.
    Here is the code at the top of the first page. I added the "?Page=linkspda .asp" part
    Code:
    <%
    If Session("BlnLoggedIn") <> True Then
    Response.Redirect("http://mywebsite.somewhere.com/login.asp?Page=linkspda.asp")
    End If
    %>
    This does take me to the login.asp page and in the address bar on the browser it shows the "http://mywebsite.somew here.com/login.asp?Page= linkspda.asp"
    The login.asp page looks like this:

    Code:
    <% 
    Response.Expires = -1000 'Make sure the browser doesn't cache this page
    Response.Buffer = True 'enables our response.redirect to work
    %>
    
    <html>
    <head><title>Password Protect your ASP pages</title>
    </head>
    <body>
    
    <%
    If Request.Form("submit") ="Login" Then 
    CheckLoginForm
    Else
    ShowLoginForm 
    End If 
    %> 
    
    <%
    Sub CheckLoginForm
    testvar = Request.QueryString("Page")
    'check if the value of the text field 'username' and 'password' are correct
    If Request.Form("username") = "test" AND Request.Form("password") = "pass" Then
    Session("BlnLoggedIn") = True
    Response.Redirect testvar
    Else
    Response.Write "<div align='center'>You are not logged in.</div><br>"
    ShowLoginForm 
    End If
    End Sub
    %> 
    
    <% Sub ShowLoginForm %>
    <div align='center'>
    <!-- start the HTML login form -->
    <form name="form" action="login.asp" method="post">
    <table>
    <tr>
            <td><font size="8">User Name :</font></td>
            <td><input type="text" style="font-size:48px" name="username"></td></tr>
    <tr>
            <td><font size="8">Password : </font></td>
            <td><input type="password" style="font-size:48px" name="password"></td></tr>
    <tr><td colspan="2"><input type="submit" style="font-size:48px" name="submit" value="Login"></td></tr>
    </table> 
    </form>
    <!-- end the HTML login form -->
    </div> 
    <% End Sub %> 
    
    </body>
    </html>
    After the "Sub CheckLoginForm" I added the line:
    testvar = Request.QuerySt ring("Page")
    and
    Response.Redire ct testvar

    The Response.Redire ct was just:
    Response.Redire ct "linkspda.a sp"

    The Request.QuerySt ring("Page") does not seem to contain anything.


    What am I doing wrong?

    Thanks,
    Scott
  • Nicodemas
    Recognized Expert New Member
    • Nov 2007
    • 164

    #2
    When the user arrives at login.asp the Query String contains the Page variable. However, when the user submits the form, the Page variable is lost because it is not included in the querystring of the action attribute on the form. You need to include it as a querystring parameter in the action attribute of the form, or you need to include it as a hidden input element of the form; but, if you include it as a hidden element, you will have to test for it using Request.Form since you are using a POST operation.

    I personally suggest you just pass it through the form as a hidden element, and change your test using the generic Request().

    Comment

    Working...