...

View Full Version : Code help - not sure how to automaticaly jump to another page



newkid
08-24-2004, 04:36 PM
I have some code I borrowed and it works fine. it's an easy login/password program (w / access back end).

1. I want to change it, when a user enters a valid User-Id & password that it automaticaly sends them to specific page (IE. valid_page.asp)

2. Is there any way to check in the page (valid_page.asp) that the previous page was login.asp (that it was called from login.asp). To prevent some one from just entering http://myserver/valid_page.asp so that they would have to go thru login.asp. and if they did try and go straight to valid_page.asp it would send them to login.asp?

PS I've been searching google and here but can't find a solution (not really sure what to search on)


Thanks for all help in advance

J.C.
To learn is a good thing and today I hope to learn something new.





<%@ Language = "VBScript" %>
<%
Option Explicit

Dim cnnLogin
Dim rstLogin
Dim strUsername, strPassword
Dim strSQL

%>
<html>
<head><title>Login Page</title>
</head>
<body bgcolor="gray">
<%
If Request.Form("action") <> "validate_login" Then
%>
<form action="login.asp" method="post">
<input type="hidden" name="action" value="validate_login" />
<table border="0">
<tr>
<td align="right">Enter User-ID:</td>
<td><input type="text" name="login" /></td>
</tr>
<tr>
<td align="right">Enter Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right"></TD>
<td><input type="submit" VALUE="Login" /></td>
</tr>
</table>
</form>
<%
Else
strSQL = "SELECT * FROM tblLoginInfo " _
& "WHERE username='" & Replace(Request.Form("login"), "'", "''") & "' " _
& "AND password='" & Replace(Request.Form("password"), "'", "''") & "';"

Set cnnLogin = Server.CreateObject("ADODB.Connection")
cnnLogin.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
& "DBQ=" & Server.MapPath("login.mdb"))

Set rstLogin = cnnLogin.Execute(strSQL)

If Not rstLogin.EOF Then
%>
<p><strong>Valid User-ID / Password</strong></p>
<a href="valid_page.asp">Click here to Continue</a>
</p>
<%
Else
%>
<p><font size="4" face="arial,helvetica"><strong>
Login Failed - Please verify username and password.
</strong></font></p>
<p>
<a href="login.asp">Try Again</a>
</p>
<%
'Response.End
End If

' Clean Up
rstLogin.Close
Set rstLogin = Nothing
cnnLogin.Close
Set cnnLogin = Nothing
End If
%>
</body>
</html>

fractalvibes
08-24-2004, 04:48 PM
If you check, and they entered a good userid and password, you could set a session variable and the response.redirect to the other page. Have some code in all subsequent pages after the login page that checks that session variable - if it is not set, redirect them back to the login page

fv

newkid
08-24-2004, 05:59 PM
Thanks fractalvibes

I've got the redirect from the login page working, having trouble with the check on the valid_page though not sure were to put the check (or what code to use) to redirect back to login page if strName is not = "valid".... here's the code on my valid_page

(login.asp)


Dim strName
strName = "valid"

Response.Redirect "valid_page.asp?name=" & strname



valid_page.asp


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Block Sales Leads (MNU)</title>
<link rel="stylesheet" type="text/css" href="Block_Style.css">
</head>
<body>
<div id="container">
<div id="header">
<h1>Ridley Block Operations<br/>
Sales Leads</h1>
<h3>Main Menu</h3>
</div>
<div id="content">
<div id="menu">
<ul>
<li><a href="menu.htm" title="Return to Main Menu">Home</a></li>
<li><a href="SalesLeads_add.asp" title="Sales Leads (Add)">Add New </a></li>
<li><a href="SalesLeads_UnProc_Sel.asp" title="Process new Sales Leads">UnProcessed</a></li>
<li><a href="SalesLeads_Proc_Sel.asp" title="Review Processed Sales Leads">Processed</a></li>
<li><a href="SalesLeads_ReportMenu.htm" title="Report Menu">Reports</a></li>
</ul>
</div>
<div id="content2">
This site is for RFI Block OFFICAL use only.
<h2> </h2>
<p>Sales Lead instructions.</p>
<ul>
<li><strong>About Home</strong></li>
<div>This Menu selection will always bring you to the Home Page (Main Menu).</div>
<li><strong>About Add New</strong></li>
<div>Allows you to add new Sales Lead records.</div>
<li><strong>About UnProcessed</strong></li>
<div>Allows you to check all new Sales Lead records. after review of the record you may add
Point of Contact (Lead POC) information, assign additional E-Mail address to send Lead to
and E-Mail Lead Record information out.</div>
<li><strong>About Processed</strong></li>
<div>This Menu selection allows you to review all Sales Lead Records that have been processed.
This is also the area were POCs can add additional comments and information on a Lead.</div>
<li><strong>About Reports</strong></li>
<div>The menu item will contain weekly, monthly and special reports there will also be a section to export data.</div>
</ul>
<div>
<div align="center"><img src="images/RBO_Logo.gif" alt="Ridley Block Logo" width="234" height="185"></div>
</div>
</div>
</div>
<div id="footer">
For comments, questions or report dead links - Please E-Mail <a href="mailto:webmaster@ridleyinc.com&amp;subject=Web%20Page%20Request&amp;Body=Line%20Please%20enter%20your%20requ est%20here" style="color: #FFFFFF">Webmaster</a>
</div>
</div>
</body>
</html>

fractalvibes
08-24-2004, 06:45 PM
I would not do that in a querystring.

If (valid username and password entered) then
Session("LoggedIn") = True
Response.redirect "valid_page.asp"
Else
Response.Write "Incorrect Username/Password"
ENd If


--- on valid_page.asp, very first thing:
If Not Session("LoggedIn") = True then
response.redirect "Login.asp"
End If

fv

newkid
08-24-2004, 08:18 PM
Thanks Much VF


J.C.
Today I have learned a new thing and that is good......



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum