More on session variables

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

    More on session variables

    I wanted to see if absolute or relative URLs had anything at all to do
    with the session variable information being lost. So, I wrote a simple
    test program. It is at www.sheldonlg.com/headertest/index.php. The
    results were not what I expected. BOTH ways lost the session information.

    All this test application does is call session_name to set a name. Then
    session_start. It prints out the name and dumps the session variables.
    It has two buttons, one for absolute header path and one for relative
    path. Each is a submit butto that goes to a page where the test is made
    as the the source of the click and then uses a header("Locatio n....)
    command to go to one of two different pages. Each of those pages dumps
    the session variables and the session name, and all pages (other than
    the index page described earlier) has session_start() ; as the first
    executable line.

    What happens is that the session variables are lost and the session
    names become PHPSESSID, the default.

    What is wrong here? It seems so exceedingly elementary. I have done
    this process so many times to set and later read session variables that
    is has become second nature to me. Why is it not working in this very
    simple application?
  • AnrDaemon

    #2
    Re: More on session variables

    Greetings, sheldonlg.
    In reply to Your message dated Wednesday, July 2, 2008, 22:55:38,
    Here is what I would like to do, but there seems to be a chicken and egg
    situation. I would like to name the session as $thename =
    'somekindoftext ' . time(); I want to do this upon entering the base
    page. Now, as I understand it, on every page I would then have:
    session_name($t hename);
    session_start() ;
    It looks you want to generate session id, not session name.
    Let me explain.
    session_name() - sets the NAME of the session variable that will be used to
    track sessions. It is the same for all users, and session_start looking for it
    to retrieve session id.
    session_id() - sets the actual session identifier, representing exact user who
    browsing your pages. Actual "name" of the *user*.
    However, where do these pages get the value of $thename from?
    That's undefined in your example, excluding some rare, monstrous variants...
    Also, if we reenter the base page where the session name is generated,
    Session name should not be generated.
    does that start a whole new session and we would lose all prior information
    from the previous named session?
    Session started by calling session_start() or session_registe r().
    Calling session_name(), session_id() does nothing on that end.
    So, here is what I see:
    in index.php:
    $sessionName = 'somekindoftext ' . time();
    session_name($s essionName);
    session_start;
    in all succeeding pages:
    What????
    Nothing.
    Create a 'session.php' like:

    <?php

    if(!array_key_e xist(session_na me(), $_REQUEST))
    {
    session_id('som ekindoftext' . strval(time())) ;
    }

    session_start() ;

    ?>

    and include it in every your file that require session handling.

    P.S.
    I've had real use of custom session ids only once:
    When I had to write CLI PHP script which were want to store some data between
    runs. I've used constant session ID made from script name and version to
    restart previously saved session.


    --
    Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

    Comment

    • sheldonlg

      #3
      Re: More on session variables

      AnrDaemon wrote:
      Greetings, sheldonlg.
      In reply to Your message dated Wednesday, July 2, 2008, 22:55:38,
      >
      >Here is what I would like to do, but there seems to be a chicken and egg
      >situation. I would like to name the session as $thename =
      >'somekindoftex t' . time(); I want to do this upon entering the base
      >page. Now, as I understand it, on every page I would then have:
      >
      >session_name($ thename);
      >session_start( );
      >
      It looks you want to generate session id, not session name.
      Let me explain.
      session_name() - sets the NAME of the session variable that will be used to
      track sessions. It is the same for all users, and session_start looking for it
      to retrieve session id.
      session_id() - sets the actual session identifier, representing exact user who
      browsing your pages. Actual "name" of the *user*.
      >
      >However, where do these pages get the value of $thename from?
      >
      That's undefined in your example, excluding some rare, monstrous variants...
      >
      >Also, if we reenter the base page where the session name is generated,
      >
      Session name should not be generated.
      >
      >does that start a whole new session and we would lose all prior information
      >from the previous named session?
      >
      Session started by calling session_start() or session_registe r().
      Calling session_name(), session_id() does nothing on that end.
      >
      >So, here is what I see:
      >
      >in index.php:
      >$sessionName = 'somekindoftext ' . time();
      >session_name($ sessionName);
      >session_star t;
      >
      >in all succeeding pages:
      >What????
      >
      Nothing.
      Create a 'session.php' like:
      >
      <?php
      >
      if(!array_key_e xist(session_na me(), $_REQUEST))
      {
      session_id('som ekindoftext' . strval(time())) ;
      }
      >
      session_start() ;
      >
      ?>
      >
      and include it in every your file that require session handling.
      >
      P.S.
      I've had real use of custom session ids only once:
      When I had to write CLI PHP script which were want to store some data between
      runs. I've used constant session ID made from script name and version to
      restart previously saved session.
      >
      >
      Thanks, that makes a lot of sense.

      Comment

      Working...