Click to See Complete Forum and Search --> : keep the login


Blelisa
12-18-2006, 08:05 AM
Hi Everyone,

I have a site that the visitor has to log in to for access to certain pages. The problem I am having is that my user logs in to gain access to one of the pages then when they try to move to another page it does not recognize that the user is logged in and asks them to do it again. How do I correct that?

Thank you in advance for any help.

nbcrockett
12-18-2006, 08:07 AM
Create a session variable that your pages check for.

Blelisa
12-18-2006, 08:26 AM
This is what I have in all my pages that require a visitor to be logged in:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<% if(session("loggedIn")<> 1)then
response.redirect("login.asp")
end if %>
<html>
<head>

And this is what I have in my verify.asp page that is used when someone logs in:
<% @LANGUAGE = VBSCRIPT %>
<% Option Explicit %>

<% 'chk_login.asp %>

<% Dim connection, check, info

'Open a database connection
Set connection = Server.CreateObject("ADODB.Connection")
connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
server.MapPath("data/hemicustreg.mdb")
connection.Open

' Call connection.open("ecommerce")

'Build the SQL query

check="SELECT * From customer WHERE username = '"_
& CStr(Request("Username")) & "'"_
& " AND pwrd='"_
& CStr(Request("Pwrd"))& "'"

'Open the record set
Set info= Server.CreateObject("ADODB.RecordSet")
Call info.Open(check, connection)
On Error Resume Next

If info.EOF THEN

'The user's login is incorrect

Call info.Close()
Call connection.Close()
Call Response.Redirect("badlogin.html")
Else

'The user's login is correct
Session("company") = info("CmpName")
Session("address") = info("Address")
Session("city") = info("City")
Session("phone") = info("number")
Session("email") = info("email")
Session("contact") = info("contact")
Session("username") = Request("Username")
Session("pwrd") = Request("pwrd")
Session("loggedIn") = True
If Request.Form("remember") = "on" Then
Session("remember")= "Yes"
Else
Session("remember") = "No"
End If

Call info.Close()
Call Response.Redirect("cookies.asp")
Call connection.Close()
End If
%>

nbcrockett
12-18-2006, 08:47 AM
Try changing:

if(session("loggedIn")<> 1)then

to:

If Session("loggedIn") <> True then

True might need quotes around it. I can't remember.

Blelisa
12-18-2006, 08:55 AM
That did it, thanks!

nbcrockett
12-18-2006, 09:07 AM
No problem.