Results 1 to 8 of 8

Thread: How to force login to access a web page

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    13
    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!

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    13
    Thanks for the info Josh. Would you happen to have a link to an example or article showing a newbie how to do this?

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    What server technology are you using? For ASP try http://www.asp101.com/ or http://www.15seconds.com/

    Josh

  5. #5
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    Here is a basic example...

    Code:
    <%
    
    '**** 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
    
    %>
    Dr_Evil
    Senior Programmer
    VS6 EE
    VS.NET EA

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    13
    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!

  7. #7
    Junior Member
    Join Date
    Jan 2000
    Location
    Akron, OH US
    Posts
    17

    Lightbulb use a frame

    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.

  8. #8
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    use a frame as suggested above called 'index.html' with your login page set as the SRC

    then put this in every other page

    Code:
    <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>
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width