...

View Full Version : if Request ==""



JPM
07-31-2004, 08:30 PM
I'm making a simple login page, and the first time the user enters I thought I would check it like so:


<%
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?

startbar
08-01-2004, 08:51 AM
try this
<%
' 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
%>

angst
08-01-2004, 06:38 PM
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
%>

Morgoth
08-01-2004, 06:40 PM
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


<%
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.

startbar
08-02-2004, 11:28 PM
sorry.. just trying to be helpful .. :(

Morgoth
08-03-2004, 07:53 AM
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.

miranda
08-03-2004, 05:35 PM
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 %>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum