Session Variables Lost - Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eddie

    Session Variables Lost - Help

    I am having difficulty in setting variables in a session, and then
    accessing those variables throughout the web pages that they click
    on. After having them set a user name and password, successfully
    authenticating against Active Directory, I send them from the
    login.php page to the index.php page. But when I get to the index.php
    page, the session ID is visible, but the session variables and values
    are not. Can you help me out? Also, I'm curious how to distinguish
    between various sessions if multiple ones are available. My files are
    below. Thanks.

    Eddie

    -- excerpt of login.php page

    start_session() ;

    $user= $_POST[u];
    $pass= $_POST[p];

    if (isset($_SESSIO N[user]) and ($_SESSION[user]==$user)){

    $_SESSION[auth] = admin_all;
    $_SESSION[user] = $user;
    $_SESSION[timelast] = time();
    $_SESSION[email] = 'testemail@test domain.com';

    header('Locatio n: http://mydomain.com/index.php');
    }

    but when I go to the on to the index.php page, I cannot see the
    results. What am I missing?


    -- excerpt of index.php page

    $sessname = session_name();
    $sessid = session_id();
    session_start() ;

    print "<pre>\nContent s of \$_COOKIE:\n";
    foreach ($_COOKIE as $k =$v) {
    print " $k = $v\n";
    }

    print "\nContents of \$_SESSION:\n";
    foreach ($_SESSION as $k =$v) {
    print " $k = $v\n";
    }
    print "</pre><br>";

    print "sessionuse r = " . $_SESSION[user] . " <br>";
    print "sessiontimelas t = " . $_SESSION[timelast] . " <br>";

    -- output of index.php page

    Contents of $_COOKIE:
    PHPSESSID = e12d796fc6e3735 69202c58d8f0968 15

    Contents of $_SESSION:
    user =
    timelast =

    Session name = PHPSESSID
    Session id = e12d796fc6e3735 69202c58d8f0968 15

    -- excerpt of php.ini file

    session.use_coo kies = 1
    session.name = PHPSESSID
    session.auto_st art = 0
    session.cookie_ lifetime = 0
    session.seriali ze_handler = php

  • Erwin Moller

    #2
    Re: Session Variables Lost - Help

    Eddie wrote:
    I am having difficulty in setting variables in a session, and then
    accessing those variables throughout the web pages that they click
    on. After having them set a user name and password, successfully
    authenticating against Active Directory, I send them from the
    login.php page to the index.php page. But when I get to the index.php
    page, the session ID is visible, but the session variables and values
    are not. Can you help me out? Also, I'm curious how to distinguish
    between various sessions if multiple ones are available. My files are
    below. Thanks.
    >
    Eddie
    Hi Eddie,

    First: A client (browser) does NOT have multiple sessions.
    It can have multiple sessions to DIFFERENT DOMAINS, but not within one.

    The session is defined by the value of PHPSESSID, which can be stored in
    a cookie, or via URL-rewritting, or even hidden var in POST.
    As long as PHP received a PHPSESSID, you have a session.

    IF PHP has a corresponding file with that id, you have a session.

    >
    -- excerpt of login.php page
    >
    start_session() ;
    >
    $user= $_POST[u];
    Why don't you use formal notation for associative arrays?
    $_POST["u"];
    $pass= $_POST[p];
    >
    if (isset($_SESSIO N[user]) and ($_SESSION[user]==$user)){
    >
    $_SESSION[auth] = admin_all;
    What is admin_all?
    Didn't you mean:
    $_SESSION["auth"] = "admin_all" ;
    or maybe
    $_SESSION["auth"] = $admin_all;


    $_SESSION[user] = $user;
    $_SESSION[timelast] = time();
    $_SESSION[email] = 'testemail@test domain.com';
    >
    header('Locatio n: http://mydomain.com/index.php');
    You forgot the exit command here.
    Setting a header will NOT stop the script.
    It runs on, and I have no clue what follows. Maybe a reset on the session?
    }
    >
    but when I go to the on to the index.php page, I cannot see the
    results. What am I missing?
    >
    >
    -- excerpt of index.php page
    >
    $sessname = session_name();
    $sessid = session_id();
    session_start() ;
    >
    print "<pre>\nContent s of \$_COOKIE:\n";
    foreach ($_COOKIE as $k =$v) {
    print " $k = $v\n";
    }
    This can be done much easier with print_r, like this:
    echo "<pre>";
    print_r($_COOKI E);
    echo "<pre>";

    same for $_POST and $_GET and $_SESSION.
    Use print_r() (with pre) to dump ANY (complex) array.

    >
    print "\nContents of \$_SESSION:\n";
    foreach ($_SESSION as $k =$v) {
    print " $k = $v\n";
    }
    print "</pre><br>";
    >
    print "sessionuse r = " . $_SESSION[user] . " <br>";
    print "sessiontimelas t = " . $_SESSION[timelast] . " <br>";
    >
    -- output of index.php page
    >
    Contents of $_COOKIE:
    PHPSESSID = e12d796fc6e3735 69202c58d8f0968 15
    >
    Contents of $_SESSION:
    user =
    timelast =
    >
    Session name = PHPSESSID
    Session id = e12d796fc6e3735 69202c58d8f0968 15
    >
    -- excerpt of php.ini file
    >
    session.use_coo kies = 1
    session.name = PHPSESSID
    session.auto_st art = 0
    session.cookie_ lifetime = 0
    session.seriali ze_handler = php
    >
    Also: are you sure you stay in the same domain after the
    header("Locatio n.....");
    ??
    Sessions cannot (easily) span domains, luckily. ;-)

    Regards,
    Erwin Moller

    Comment

    • Erwin Moller

      #3
      Re: Session Variables Lost - Help

      Erwin Moller wrote:
      <snip>

      PS: Make sure you have ALL error/notices reporting on.

      add above your script:
      error_reporting (E_ALL);

      Regards,
      Erwin Moller

      Comment

      • 4sak3n 0ne

        #4
        Re: Session Variables Lost - Help

        On Aug 31, 6:58 am, Eddie <eddieandr...@g mail.comwrote:
        I am having difficulty in setting variables in a session, and then
        accessing those variables throughout the web pages that they click
        on. After having them set a user name and password, successfully
        authenticating against Active Directory, I send them from the
        login.php page to the index.php page. But when I get to the index.php
        page, the session ID is visible, but the session variables and values
        are not. Can you help me out? Also, I'm curious how to distinguish
        between various sessions if multiple ones are available. My files are
        below. Thanks.
        >
        Eddie
        >
        -- excerpt of login.php page
        >
        start_session() ;
        >
        $user= $_POST[u];
        $pass= $_POST[p];
        >
        if (isset($_SESSIO N[user]) and ($_SESSION[user]==$user)){
        >
        $_SESSION[auth] = admin_all;
        $_SESSION[user] = $user;
        $_SESSION[timelast] = time();
        $_SESSION[email] = 'testem...@test domain.com';
        >
        header('Locatio n:http://mydomain.com/index.php');
        >
        }
        >
        but when I go to the on to the index.php page, I cannot see the
        results. What am I missing?
        >
        -- excerpt of index.php page
        >
        $sessname = session_name();
        $sessid = session_id();
        session_start() ;
        >
        print "<pre>\nContent s of \$_COOKIE:\n";
        foreach ($_COOKIE as $k =$v) {
        print " $k = $v\n";
        >
        }
        >
        print "\nContents of \$_SESSION:\n";
        foreach ($_SESSION as $k =$v) {
        print " $k = $v\n";}
        >
        print "</pre><br>";
        >
        print "sessionuse r = " . $_SESSION[user] . " <br>";
        print "sessiontimelas t = " . $_SESSION[timelast] . " <br>";
        >
        -- output of index.php page
        >
        Contents of $_COOKIE:
        PHPSESSID = e12d796fc6e3735 69202c58d8f0968 15
        >
        Contents of $_SESSION:
        user =
        timelast =
        >
        Session name = PHPSESSID
        Session id = e12d796fc6e3735 69202c58d8f0968 15
        >
        -- excerpt of php.ini file
        >
        session.use_coo kies = 1
        session.name = PHPSESSID
        session.auto_st art = 0
        session.cookie_ lifetime = 0
        session.seriali ze_handler = php
        start_session() isn't a php function (unless you declared a function
        by that name I didn't notice), replace it with session_start() .

        Comment

        • Eddie

          #5
          Re: Session Variables Lost - Help

          On Aug 31, 12:37 pm, 4sak3n 0ne <4sak3n...@gmai l.comwrote:
          On Aug 31, 6:58 am, Eddie <eddieandr...@g mail.comwrote:
          >
          >
          >
          I am having difficulty in setting variables in a session, and then
          accessing those variables throughout the web pages that they click
          on. After having them set a user name and password, successfully
          authenticating against Active Directory, I send them from the
          login.php page to the index.php page. But when I get to the index.php
          page, the session ID is visible, but the session variables and values
          are not. Can you help me out? Also, I'm curious how to distinguish
          between various sessions if multiple ones are available. My files are
          below. Thanks.
          >
          Eddie
          >
          -- excerpt of login.php page
          >
          start_session() ;
          >
          $user= $_POST[u];
          $pass= $_POST[p];
          >
          if (isset($_SESSIO N[user]) and ($_SESSION[user]==$user)){
          >
          $_SESSION[auth] = admin_all;
          $_SESSION[user] = $user;
          $_SESSION[timelast] = time();
          $_SESSION[email] = 'testem...@test domain.com';
          >
          header('Locatio n:http://mydomain.com/index.php');
          >
          }
          >
          but when I go to the on to the index.php page, I cannot see the
          results. What am I missing?
          >
          -- excerpt of index.php page
          >
          $sessname = session_name();
          $sessid = session_id();
          session_start() ;
          >
          print "<pre>\nContent s of \$_COOKIE:\n";
          foreach ($_COOKIE as $k =$v) {
          print " $k = $v\n";
          >
          }
          >
          print "\nContents of \$_SESSION:\n";
          foreach ($_SESSION as $k =$v) {
          print " $k = $v\n";}
          >
          print "</pre><br>";
          >
          print "sessionuse r = " . $_SESSION[user] . " <br>";
          print "sessiontimelas t = " . $_SESSION[timelast] . " <br>";
          >
          -- output of index.php page
          >
          Contents of $_COOKIE:
          PHPSESSID = e12d796fc6e3735 69202c58d8f0968 15
          >
          Contents of $_SESSION:
          user =
          timelast =
          >
          Session name = PHPSESSID
          Session id = e12d796fc6e3735 69202c58d8f0968 15
          >
          -- excerpt of php.ini file
          >
          session.use_coo kies = 1
          session.name = PHPSESSID
          session.auto_st art = 0
          session.cookie_ lifetime = 0
          session.seriali ze_handler = php
          >
          start_session() isn't a php function (unless you declared a function
          by that name I didn't notice), replace it with session_start() .
          You're right. My code says session_start() . :-)

          Comment

          • stacey

            #6
            Re: Session Variables Lost - Help

            On Aug 31, 3:02 pm, Eddie <eddieandr...@g mail.comwrote:
            On Aug 31, 12:37 pm, 4sak3n 0ne <4sak3n...@gmai l.comwrote:
            >
            >
            >
            On Aug 31, 6:58 am, Eddie <eddieandr...@g mail.comwrote:
            >
            I am having difficulty in setting variables in a session, and then
            accessing those variables throughout the web pages that they click
            on. After having them set a user name and password, successfully
            authenticating against Active Directory, I send them from the
            login.php page to the index.php page. But when I get to the index.php
            page, the session ID is visible, but the session variables and values
            are not. Can you help me out? Also, I'm curious how to distinguish
            between various sessions if multiple ones are available. My files are
            below. Thanks.
            >
            Eddie
            >
            -- excerpt of login.php page
            >
            start_session() ;
            >
            $user= $_POST[u];
            $pass= $_POST[p];
            >
            if (isset($_SESSIO N[user]) and ($_SESSION[user]==$user)){
            >
            $_SESSION[auth] = admin_all;
            $_SESSION[user] = $user;
            $_SESSION[timelast] = time();
            $_SESSION[email] = 'testem...@test domain.com';
            >
            header('Locatio n:http://mydomain.com/index.php');
            >
            }
            >
            but when I go to the on to the index.php page, I cannot see the
            results. What am I missing?
            >
            -- excerpt of index.php page
            >
            $sessname = session_name();
            $sessid = session_id();
            session_start() ;
            >
            print "<pre>\nContent s of \$_COOKIE:\n";
            foreach ($_COOKIE as $k =$v) {
            print " $k = $v\n";
            >
            }
            >
            print "\nContents of \$_SESSION:\n";
            foreach ($_SESSION as $k =$v) {
            print " $k = $v\n";}
            >
            print "</pre><br>";
            >
            print "sessionuse r = " . $_SESSION[user] . " <br>";
            print "sessiontimelas t = " . $_SESSION[timelast] . " <br>";
            >
            -- output of index.php page
            >
            Contents of $_COOKIE:
            PHPSESSID = e12d796fc6e3735 69202c58d8f0968 15
            >
            Contents of $_SESSION:
            user =
            timelast =
            >
            Session name = PHPSESSID
            Session id = e12d796fc6e3735 69202c58d8f0968 15
            >
            -- excerpt of php.ini file
            >
            session.use_coo kies = 1
            session.name = PHPSESSID
            session.auto_st art = 0
            session.cookie_ lifetime = 0
            session.seriali ze_handler = php
            >
            start_session() isn't a php function (unless you declared a function
            by that name I didn't notice), replace it with session_start() .
            >
            You're right. My code says session_start() . :-)
            This is most likely not your problem, but I thought I'd mention it
            because I just had the same thing happen to me today.

            If you have anything like Zone Alarm installed, make sure it isn't
            messing with your sessions. Mine was, and as soon as I disabled it,
            everything worked fine.

            Comment

            • Rik Wasmus

              #7
              Re: Session Variables Lost - Help

              On Fri, 31 Aug 2007 15:58:43 +0200, Eddie <eddieandrews@g mail.comwrote:
              I am having difficulty in setting variables in a session, and then
              accessing those variables throughout the web pages that they click
              on. After having them set a user name and password, successfully
              authenticating against Active Directory, I send them from the
              login.php page to the index.php page. But when I get to the index.php
              page, the session ID is visible, but the session variables and values
              are not. Can you help me out? Also, I'm curious how to distinguish
              between various sessions if multiple ones are available.
              Multiple sessions in a single request are not really supported using
              'normal' PHP. It is theoretically possible, but it would require a lot of
              tinkering, and normally wouldn't be something you want.
              -- excerpt of login.php page
              >
              start_session() ;
              >
              $user= $_POST[u];
              $pass= $_POST[p];
              >
              if (isset($_SESSIO N[user]) and ($_SESSION[user]==$user)){
              How does $_SESSION['user'] (mind the quotes as indicated earlier) get set
              _before_ this if statement? In these excerpts it will not be set anywhere,
              so all the code in the if statement will not run?
              >
              $_SESSION[auth] = admin_all;
              $_SESSION[user] = $user;
              $_SESSION[timelast] = time();
              $_SESSION[email] = 'testemail@test domain.com';
              >
              header('Locatio n: http://mydomain.com/index.php');
              }
              >
              but when I go to the on to the index.php page, I cannot see the
              results. What am I missing?
              Heed Erwin's advice about error_reporting (E_ALL); (and possibly an
              ini_set('displa y_errors',true) ; If these are true excerpts there are more
              problems then just the carrying on of a session.
              --
              Rik Wasmus

              My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
              quality is certainly an option.

              Comment

              • Aaron Saray

                #8
                Re: Session Variables Lost - Help

                On Aug 31, 10:35 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
                On Fri, 31 Aug 2007 15:58:43 +0200, Eddie <eddieandr...@g mail.comwrote:
                I am having difficulty in setting variables in a session, and then
                accessing those variables throughout the web pages that they click
                on. After having them set a user name and password, successfully
                authenticating against Active Directory, I send them from the
                login.php page to the index.php page. But when I get to the index.php
                page, the session ID is visible, but the session variables and values
                are not. Can you help me out? Also, I'm curious how to distinguish
                between various sessions if multiple ones are available.
                >
                Multiple sessions in a single request are not really supported using
                'normal' PHP. It is theoretically possible, but it would require a lot of
                tinkering, and normally wouldn't be something you want.
                >
                -- excerpt of login.php page
                >
                start_session() ;
                >
                $user= $_POST[u];
                $pass= $_POST[p];
                >
                if (isset($_SESSIO N[user]) and ($_SESSION[user]==$user)){
                >
                How does $_SESSION['user'] (mind the quotes as indicated earlier) get set
                _before_ this if statement? In these excerpts it will not be set anywhere,
                so all the code in the if statement will not run?
                >
                >
                >
                $_SESSION[auth] = admin_all;
                $_SESSION[user] = $user;
                $_SESSION[timelast] = time();
                $_SESSION[email] = 'testem...@test domain.com';
                >
                header('Locatio n:http://mydomain.com/index.php');
                }
                >
                but when I go to the on to the index.php page, I cannot see the
                results. What am I missing?
                >
                Heed Erwin's advice about error_reporting (E_ALL); (and possibly an
                ini_set('displa y_errors',true) ; If these are true excerpts there are more
                problems then just the carrying on of a session.
                --
                Rik Wasmus
                >
                My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
                quality is certainly an option.
                I would try using session_write_c lose() right before your header()
                statement - and see if that helps. From time to time, setting new
                variables in sessions won't stick for whatever reason, unless you
                close a session on that page first.

                Comment

                • Eddie

                  #9
                  Re: Session Variables Lost - Help


                  Thanks for all the tips and suggestions. It works now!

                  Eddie

                  Comment

                  Working...