SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with session vars

    I am having trouble with sessions variables and multiple documents. I have a login page which looks like this and the sessions variables work fine here.

    PHP Code:
     
    <?
    session_start();
    if ($_GET['session'] == "close") {
     $_SESSION['status'] = "end";
     header("Location: $PHP_SELF");
    }
    if (!isset($status)) {

     if ($_POST['validate'] == "yes") {
      $_SESSION['password'] = md5($_POST['pw']);
      $_SESSION['status'] = "validate";
      header("Location: $PHP_SELF");
     }
     $message = "Please enter your password to log on:";
     include 'log_form.php';
    } elseif ($_SESSION['status'] == "validate") {
     // check pw
     // Connect to database
     include 'functions.php';
     $table = "logon";
     $sqlquery = "SELECT * FROM $table";
     $result = dbconnect($sqlquery);
     $checkPW = mysql_result($result,$i,"password");
     mysql_close();
     if ($password == $checkPW) {
      $_SESSION['status'] = "goodPass";
      unset($_SESSION['password']);
     } else {
      $_SESSION['status'] = "badPass";
     }
     header("Location: $PHP_SELF");
    } elseif ($_SESSION['status'] == "goodPass") {
     header("Location: admin.php");
    } elseif ($_SESSION['status'] == "badPass") {
     $message = "<i>Logon incorrect. Please try again </i>";
     include 'log_form.php';
     // release session variables
     session_unset();
    } else {
     session_unset();
     session_write_close();
     $message = "You have successfully logged off. To log on again please enter your password.<br><br>";
     include 'log_form.php';
    }
    ?>
    but then when the good password is entered and the user is redirected to "admin.php" I seem to lose the session variable "status". Here's the code I use:

    PHP Code:
    <?
    if($_SESSION['status']=="goodPass") {
    // stuff
    } else {
     $message="Your session has expired, please log on again";
     include 'log_form.php';
    }
    No matter what I do it always goes to the else here.

    Thanks to anyone who can help

  2. #2
    lean mean coding machine cosmo's Avatar
    Join Date
    Aug 2001
    Location
    the cosmos
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you will need to add the session_start() function at the very top of your admin.php page, to be able to access the session variables.
    Luthfur R. - Web Developer
    PHP Lite.com - Professional PHP Scripts and Web Applications
    Calendar Express 2 - Web Based Calendar and Event Publishing System


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
  •