vbscript, asp, and response.redirect - urgent help plz 
Author Message
 vbscript, asp, and response.redirect - urgent help plz

HELP!

I'm using a database to verify a username and password before letting a user
into the main web site.
The database stuff seems fine - if I enter a valid name and password, it
prints the appropriate message,
if I enter an invalid name it says No records found.  That's fine.

However, I'm having a problem with how to send the user to a different page
once the LOGIN.ASP deals with it.
I have included the output from the webpage, the HTML and the ASP.
Any help is appreciated, and I'm supposed to have this ready in about 8
hours...

============================================
OUTPUT
=======

No records found
Response object error 'ASP 0156 : 80004005'

Header Error

/test/login.asp, line 42

The HTTP headers are already written to the client browser. Any HTTP header
modifications must be made before writing page content.

============================================
HTML
=====
<HTML>
<HEAD>
<TITLE>Login Page</TITLE>
</HEAD>

<BODY>

<FORM NAME="form" METHOD="POST" ACTION="login.asp">
Username: <INPUT TYPE="text" NAME="username"><BR>
Password: <INPUT TYPE="text" NAME="password"><BR>
<INPUT TYPE="SUBMIT" NAME="LOGIN">
</FORM>

</BODY>
</HTML>

ASP
===
<HTML>
<HEAD>
<TITLE>LOGIN AUTHORISATION PAGE</TITLE>
</HEAD>

<BODY BGCOLOR="WHITE">
<BR><BR><BR>
<CENTER>


<%
'Request.form function request the value from the form.
iUsername = server.HtmlEncode(request.form("username"))
iPassword = server.HtmlEncode(request.form("password"))
iRedirect = server.HtmlEncode(request.form("redirect"))

'Create object. In this case Connection to a database
Set Conn = Server.CreateObject("ADODB.Connection")

'Select provider
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"

'Select data source.
Conn.ConnectionString = "Data Source=" & Server.MapPath ("login.mdb")

'Open the connection
Conn.Open

'Create recordset
Set Rs = Server.CreateObject("ADODB.Recordset")

'Open recordset with the connection which we have created earlier
Rs.Open "SELECT * from Table1;", Conn, 1,3

'response.write Build & "<BR>"
rs.Filter = "username = '"&iUserName&"'"

If rs.BOF And rs.EOF Then
Response.Write("<BR><BR><BR><CENTER><b>No records found</b></CENTER>")
Response.Redirect("login.html")
End If

if rs("password") <> iPassword then
 response.redirect("login.html")
end if

'if we get here, then we're logged in properly
Response.Redirect("index.html")

'Deinitialize the Connection and Recordset
set Rs = nothing
set Conn = nothing
%>

</CENTER>
</BODY>
</HTML>



Thu, 04 Mar 2004 19:55:19 GMT  
 vbscript, asp, and response.redirect - urgent help plz
Hi Anthony!

If you re-organize your ASP page just a bit, it will make it easier to
handle this situation. Here's a general outline I use for many ASP pages:

Dim vars, set default values
Get values from form (if present)
    If called from form, then lookup user
        If User found Then
            Display welcome message, or start page
        Else
            Display "Bad User or Password" message
            Display login form
        End If
    Else
        Display login form
    End If

Where it shows "Display login form" above, I usually put that into a sub, so
I don't duplicate the code, or I use flags to indicate what parts are
displayed.

Here's a simple login page:


<%
    Dim cn, StrSQL, rsUser
    Dim UID, PID
    Dim ShowLogin, ErrMsg, UserOK

    Set cn = Server.CreateObject("ADODB.Connection")
    Set rsUser = Server.CreateObject("ADODB.Recordset")
    ErrMsg = ""
    ShowLogin = True
    UID = ""
    PID = ""
    UserOK = False

Sub LoginForm()
%><H3>Please Login</H3>
<FORM METHOD="POST" ACTION="login.asp" ID="Login" NAME="Login">
<INPUT TYPE="HIDDEN" NAME="FORMNAME" ID="FORMNAME" VALUE="LOGIN">
User Name: <INPUT TYPE="TEXT" NAME="UID" ID="UID" VALUE=""><BR>
Password: <INPUT TYPE="PASSWORD" NAME="PID" ID="PID" VALUE=""><BR>
<INPUT TYPE="SUBMIT" NAME="SUBMIT" ID="SUBMIT"><BR>
</FORM>
<BR>
<%
End Sub

' Were we called by the login form?
    If Request.Form("FORMNAME") = "LOGIN" Then
        ' Get the values entered
        UID = Request.Form("UID")
        PID = Request.Form("PID")
        ' Lookup the user
        cn.open (use your conection string stuff here)
        StrSQL = "SELECT * FROM Users WHERE User_ID = '" & UID & "' and
PASSWORD = '" & PID & "'"
        rsUser.Open StrSQL, cn
        If rsUser.State <> 0 Then
            If not (rsUser.BOF and rsUser.EOF) Then ' we got a record back
                UserOK = True
                ShowLogin = False
                ErrMsg = "Welcome!"
            Else
                ErrMsg = "The User ID or Password Entered was Incorrect,
please try again"
            End If
        End If
    End If

    If ErrMsg <> "" Then

%><FONT COLOR="FF0000"><% =ErrMsg %></FONT></BR>
<%
    End If
    If ShowLogin Then
        LoginForm
    Else
... show your welcome page
    End If
%>

Hope that helps...

Sloan


Quote:
> HELP!

> I'm using a database to verify a username and password before letting a
user
> into the main web site.
> The database stuff seems fine - if I enter a valid name and password, it
> prints the appropriate message,
> if I enter an invalid name it says No records found.  That's fine.

> However, I'm having a problem with how to send the user to a different
page
> once the LOGIN.ASP deals with it.
> I have included the output from the webpage, the HTML and the ASP.
> Any help is appreciated, and I'm supposed to have this ready in about 8
> hours...

> ============================================
> OUTPUT
> =======

> No records found
> Response object error 'ASP 0156 : 80004005'

> Header Error

> /test/login.asp, line 42

> The HTTP headers are already written to the client browser. Any HTTP
header
> modifications must be made before writing page content.

> ============================================
> HTML
> =====
> <HTML>
> <HEAD>
> <TITLE>Login Page</TITLE>
> </HEAD>

> <BODY>

> <FORM NAME="form" METHOD="POST" ACTION="login.asp">
> Username: <INPUT TYPE="text" NAME="username"><BR>
> Password: <INPUT TYPE="text" NAME="password"><BR>
> <INPUT TYPE="SUBMIT" NAME="LOGIN">
> </FORM>

> </BODY>
> </HTML>

> ASP
> ===
> <HTML>
> <HEAD>
> <TITLE>LOGIN AUTHORISATION PAGE</TITLE>
> </HEAD>

> <BODY BGCOLOR="WHITE">
> <BR><BR><BR>
> <CENTER>


> <%
> 'Request.form function request the value from the form.
> iUsername = server.HtmlEncode(request.form("username"))
> iPassword = server.HtmlEncode(request.form("password"))
> iRedirect = server.HtmlEncode(request.form("redirect"))

> 'Create object. In this case Connection to a database
> Set Conn = Server.CreateObject("ADODB.Connection")

> 'Select provider
> Conn.Provider = "Microsoft.Jet.OLEDB.4.0"

> 'Select data source.
> Conn.ConnectionString = "Data Source=" & Server.MapPath ("login.mdb")

> 'Open the connection
> Conn.Open

> 'Create recordset
> Set Rs = Server.CreateObject("ADODB.Recordset")

> 'Open recordset with the connection which we have created earlier
> Rs.Open "SELECT * from Table1;", Conn, 1,3

> 'response.write Build & "<BR>"
> rs.Filter = "username = '"&iUserName&"'"

> If rs.BOF And rs.EOF Then
> Response.Write("<BR><BR><BR><CENTER><b>No records found</b></CENTER>")
> Response.Redirect("login.html")
> End If

> if rs("password") <> iPassword then
>  response.redirect("login.html")
> end if

> 'if we get here, then we're logged in properly
> Response.Redirect("index.html")

> 'Deinitialize the Connection and Recordset
> set Rs = nothing
> set Conn = nothing
> %>

> </CENTER>
> </BODY>
> </HTML>



Thu, 04 Mar 2004 21:45:02 GMT  
 vbscript, asp, and response.redirect - urgent help plz
You need:

<%response.buffer = TRUE%>

***NOTE: This needs to be the first line in your ASP page

Ben.


Quote:
> HELP!

> I'm using a database to verify a username and password before letting a
user
> into the main web site.
> The database stuff seems fine - if I enter a valid name and password, it
> prints the appropriate message,
> if I enter an invalid name it says No records found.  That's fine.

> However, I'm having a problem with how to send the user to a different
page
> once the LOGIN.ASP deals with it.
> I have included the output from the webpage, the HTML and the ASP.
> Any help is appreciated, and I'm supposed to have this ready in about 8
> hours...

> ============================================
> OUTPUT
> =======

> No records found
> Response object error 'ASP 0156 : 80004005'

> Header Error

> /test/login.asp, line 42

> The HTTP headers are already written to the client browser. Any HTTP
header
> modifications must be made before writing page content.

> ============================================
> HTML
> =====
> <HTML>
> <HEAD>
> <TITLE>Login Page</TITLE>
> </HEAD>

> <BODY>

> <FORM NAME="form" METHOD="POST" ACTION="login.asp">
> Username: <INPUT TYPE="text" NAME="username"><BR>
> Password: <INPUT TYPE="text" NAME="password"><BR>
> <INPUT TYPE="SUBMIT" NAME="LOGIN">
> </FORM>

> </BODY>
> </HTML>

> ASP
> ===
> <HTML>
> <HEAD>
> <TITLE>LOGIN AUTHORISATION PAGE</TITLE>
> </HEAD>

> <BODY BGCOLOR="WHITE">
> <BR><BR><BR>
> <CENTER>


> <%
> 'Request.form function request the value from the form.
> iUsername = server.HtmlEncode(request.form("username"))
> iPassword = server.HtmlEncode(request.form("password"))
> iRedirect = server.HtmlEncode(request.form("redirect"))

> 'Create object. In this case Connection to a database
> Set Conn = Server.CreateObject("ADODB.Connection")

> 'Select provider
> Conn.Provider = "Microsoft.Jet.OLEDB.4.0"

> 'Select data source.
> Conn.ConnectionString = "Data Source=" & Server.MapPath ("login.mdb")

> 'Open the connection
> Conn.Open

> 'Create recordset
> Set Rs = Server.CreateObject("ADODB.Recordset")

> 'Open recordset with the connection which we have created earlier
> Rs.Open "SELECT * from Table1;", Conn, 1,3

> 'response.write Build & "<BR>"
> rs.Filter = "username = '"&iUserName&"'"

> If rs.BOF And rs.EOF Then
> Response.Write("<BR><BR><BR><CENTER><b>No records found</b></CENTER>")
> Response.Redirect("login.html")
> End If

> if rs("password") <> iPassword then
>  response.redirect("login.html")
> end if

> 'if we get here, then we're logged in properly
> Response.Redirect("index.html")

> 'Deinitialize the Connection and Recordset
> set Rs = nothing
> set Conn = nothing
> %>

> </CENTER>
> </BODY>
> </HTML>



Fri, 05 Mar 2004 07:13:18 GMT  
 vbscript, asp, and response.redirect - urgent help plz
Hi,

Hope this is not too late:), you should specify Response.Buffer = True at
the very first of your ASP page. This has been addressed in one of our KB
articles and I am sure you will be able to find out this article if you
search it with the error number.

Regards,
Ben



Fri, 05 Mar 2004 19:00:26 GMT  
 vbscript, asp, and response.redirect - urgent help plz
Thanks!  I appreciate it!


Quote:
> You need:

> <%response.buffer = TRUE%>

> ***NOTE: This needs to be the first line in your ASP page

> Ben.



> > HELP!

> > I'm using a database to verify a username and password before letting a
> user
> > into the main web site.
> > The database stuff seems fine - if I enter a valid name and password, it
> > prints the appropriate message,
> > if I enter an invalid name it says No records found.  That's fine.

> > However, I'm having a problem with how to send the user to a different
> page
> > once the LOGIN.ASP deals with it.
> > I have included the output from the webpage, the HTML and the ASP.
> > Any help is appreciated, and I'm supposed to have this ready in about 8
> > hours...

> > ============================================
> > OUTPUT
> > =======

> > No records found
> > Response object error 'ASP 0156 : 80004005'

> > Header Error

> > /test/login.asp, line 42

> > The HTTP headers are already written to the client browser. Any HTTP
> header
> > modifications must be made before writing page content.

> > ============================================
> > HTML
> > =====
> > <HTML>
> > <HEAD>
> > <TITLE>Login Page</TITLE>
> > </HEAD>

> > <BODY>

> > <FORM NAME="form" METHOD="POST" ACTION="login.asp">
> > Username: <INPUT TYPE="text" NAME="username"><BR>
> > Password: <INPUT TYPE="text" NAME="password"><BR>
> > <INPUT TYPE="SUBMIT" NAME="LOGIN">
> > </FORM>

> > </BODY>
> > </HTML>

> > ASP
> > ===
> > <HTML>
> > <HEAD>
> > <TITLE>LOGIN AUTHORISATION PAGE</TITLE>
> > </HEAD>

> > <BODY BGCOLOR="WHITE">
> > <BR><BR><BR>
> > <CENTER>


> > <%
> > 'Request.form function request the value from the form.
> > iUsername = server.HtmlEncode(request.form("username"))
> > iPassword = server.HtmlEncode(request.form("password"))
> > iRedirect = server.HtmlEncode(request.form("redirect"))

> > 'Create object. In this case Connection to a database
> > Set Conn = Server.CreateObject("ADODB.Connection")

> > 'Select provider
> > Conn.Provider = "Microsoft.Jet.OLEDB.4.0"

> > 'Select data source.
> > Conn.ConnectionString = "Data Source=" & Server.MapPath ("login.mdb")

> > 'Open the connection
> > Conn.Open

> > 'Create recordset
> > Set Rs = Server.CreateObject("ADODB.Recordset")

> > 'Open recordset with the connection which we have created earlier
> > Rs.Open "SELECT * from Table1;", Conn, 1,3

> > 'response.write Build & "<BR>"
> > rs.Filter = "username = '"&iUserName&"'"

> > If rs.BOF And rs.EOF Then
> > Response.Write("<BR><BR><BR><CENTER><b>No records found</b></CENTER>")
> > Response.Redirect("login.html")
> > End If

> > if rs("password") <> iPassword then
> >  response.redirect("login.html")
> > end if

> > 'if we get here, then we're logged in properly
> > Response.Redirect("index.html")

> > 'Deinitialize the Connection and Recordset
> > set Rs = nothing
> > set Conn = nothing
> > %>

> > </CENTER>
> > </BODY>
> > </HTML>



Fri, 05 Mar 2004 20:35:59 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. vbscript, asp, and response.redirect - urgent help plz

2. New Index or Reindexing for DBase IV Database

3. How to import text files into PDOX tables

4. Byte manipulation?

5. Response Redirect doesn't Work - No me funciona Response Redirect

6. Response.Redirect and Validation Controls with ASP.NET

7. Help plz,plz,plz!!!

8. HELP PLZ,plz,plz!!

9. TChart2FX in D1

10. ASP problem: response.redirect

11. ASP redirect Urgent

12. ReportSmith 2.5 Paradox password

 

 
Powered by phpBB® Forum Software