Click to See Complete Forum and Search --> : How to force login to access a web page
jdxah
Jan 24th, 2001, 01:09 PM
I know next to nothing about JavaScript and was wondering if someone could help me out.
I have a login page to a site on our intranet that I created using code from javascript.internet.com. I was wondering how to force a visitor to perform a succesful login. In other words, If a user enters their Username and Password correctly and are sent to Page1.htm, I don't want that person to be able to bookmark Page1.htm to bypass the login page.
Thanks!
JoshT
Jan 24th, 2001, 01:26 PM
You need to check if the user is logged in on every page you want to secure, if they are not send them back to the login page. You have to do it server-side, not with client side Javascript. You'd use a Cookie, SessionID, or Get String to keep track of whether they are logged in.
Josh
jdxah
Jan 24th, 2001, 01:48 PM
Thanks for the info Josh. Would you happen to have a link to an example or article showing a newbie how to do this?
JoshT
Jan 24th, 2001, 02:16 PM
What server technology are you using? For ASP try http://www.asp101.com/ or http://www.15seconds.com/
Josh
Dr_Evil
Jan 24th, 2001, 02:22 PM
Here is a basic example...
<%
'**** This should be placed on the login page ****
'Create Session Variables
Session("UserID") = Request("txtUserID")
Session("Password") = Request("txtPassword")
'**** Place this on the pages you wish to secure ****
' Check to see if the user needs to be redirected to another page ==
If Session("UserID") = "" Or Session("Password") = "" Then
'== Redirect to login page ==
Response.Redirect "login.asp"
End If
%>
jdxah
Jan 24th, 2001, 03:03 PM
Server Tech: W2K 2000
I am sorry if I am sounding like an idiot here but I cut and pasted Dr Evil's code into a couple of test pages and when I opened the document that contained the following code:
<html>
<head>
<title>New Page</title>
<script language="JavaScript">
If Session("UserID") = "" Or Session("Password") = "" Then;
Response.Redirect "login.htm";
End If;
</Script>
</head>
<body>
<Center>It Worked!</center>
</body>
</html>
I got a Runtime error:
Line: 4
Error: Expected ';'
Which doesn't make sense to me because that is the <script language="JavaScript"> Line.
I don't really know what I am doing here so please be patient!
dlute123
Jan 31st, 2001, 10:21 PM
Make your login page in a framed with a 1 pixel frame at the bottom of the frame.
I have done this on some sites and it seems to work ok.
Mark Sreeves
Feb 1st, 2001, 03:37 AM
use a frame as suggested above called 'index.html' with your login page set as the SRC
then put this in every other page
<HTML>
<HEAD>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<script language="JavaScript"><!--
if (parent.location.href == self.location.href)
window.location.href = 'index.html';
//--></script>
</HEAD>
<BODY>
</BODY>
</HTML>
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.