Advanced Search

Page 3 of 3 FirstFirst 123
Results 21 to 22 of 22

Thread: password redirect to page

  1. #21
    Join Date
    Mar 2008
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    The log in page has the code:
    PHP Code:
    <?php 

    $sites 
    = array( 
       
    'password1'   => 'http://www.kgcr.org/1woofter/test1.php'
       
    'password2'      => 'http://www.colbyberean.com/jobs.php'
       
    'password3' => 'http://www.kgrd.org' 
    ); 

    $password = isset($_POST['password']) ? trim($_POST['password']) : ''
    @
    session_start(); 
    @
    session_register("logged_in"); 
    $_SESSION["logged_in"] = 1;  

    if(
    $password && isset($sites[$password])) { 
       
    header('Location: ' $sites[$password]); 

    ?> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <style type="text/css"> 
    body {margin: 0;padding: 0;background:#222 url('splash.gif') no-repeat top left;} 
    #login {margin: 245px 0 0 245px;} 
    #login p {margin: 2px 0 0 45px;} 
    #login input {padding: 5px;color: #666} 
    #login input:focus {color: #000} 
    </style> 
    </head> 
    <body> 
    <div id="login"> 
    <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> 
      <input type="password" name="password" size="20" maxlength="100" /> 
      <p><input type="submit" value="Submit" /></p> 
    </form> 
    </div> 
    </body> 
    </html>

    The protected page has the following script about the <head>:
    PHP Code:
    <?php 
    @session_start(); 
    if (
    $_SESSION["logged_in"] !== 1) { 
    exit(); 
    // or output an error message of your choice, then exit() 

    ?>
    Last edited by Snookerman; 04-22-2009 at 09:02 AM. Reason: added [php] tags

  2. #22
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    Try this:

    Code:
    @session_start();
    if ($_SESSION["logged_in"] !== 1) {
    echo "<b>You must be logged in to view this page!</b>";
    
    exit();
    }

    Or, You can either redirect the user to the login page itself if ($_SESSION["logged_in"] !== 1) which is usually what people do...

    Just replace the login.php in below code, if the name is different:
    Code:
    @session_start();
    if ($_SESSION["logged_in"] !== 1) {
    header("Location = login.php");
    
    exit();
    }
    I am a beginner too in php but this is a simple code, so I think I could help.
    Last edited by borris83; 04-11-2009 at 11:53 AM.

  3. The Following User Says Thank You to borris83 For This Useful Post:

    claass (04-11-2009)

Tags for this Thread

Bookmarks

Posting Permissions

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