Question Regarding Session ID

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

    Question Regarding Session ID

    I'm new to session id variables. I'm trying to write records containing the
    session id to a log file but the session id keeps disappearing. I'm using
    session_registe r() because the site has register_global s = On (Hosted web
    site Php Version 4.3.3).

    If I work on my local Windows XP computer and I start up a browser window
    the first printf statement
    printf ("This is the SID = $szTmp01<br>"); results in:

    This is the SID =

    Which is blank. The second print statement gives.
    This is the session_id = PHPSESSID=9ebb9 5e5a3a68662c5ff 32c2db358222

    which seems to work Ok.

    When I execute the script on the hosted web site the result is:
    This is the SID =
    This is the session_id =

    Can anyone explain what I'm doing wrong and why SID does not seem to have or
    retain a value?

    Thanks,
    Doug

    --------------------------------------------------

    <?php
    session_start() ;
    error_reporting (E_ALL);
    $szTmp01 = '';

    $szTmp01 = SID;
    printf ("This is the SID = $szTmp01<br>");

    if(!session_is_ registered("ses sion_id"))
    {
    session_registe r("session_id") ;
    }

    $self_url = $_SERVER['PHP_SELF'];
    if(IsSet($HTTP_ SESSION_VARS["session_id "]) &&
    $HTTP_SESSION_V ARS["session_id "])
    {
    $session_id = $HTTP_SESSION_V ARS["session_id "];
    $href = "$self_url?$szT mp01";
    }
    else
    {
    $session_id = SID;
    session_registe r("session_id") ;
    $href = $self_url;
    }
    printf ("This is the session_id = $session_id<br> ");
    $MyVar = LogSession();
    ?>

    <?php

    function LogSession()
    {
    global $session_id;
    global $self_url;
    global $HTTP_SESSION_V ARS;
    global $href;

    if(!session_is_ registered('ses sion_id'))
    {
    $session_id = SID;
    session_registe r('session_id') ;
    }

    $dtime = date('r');

    $session_id = $HTTP_SESSION_V ARS["session_id "] ;

    $rec_log = "Date: $dtime | SID: $session_id \n";
    $fp = fopen("SLog/logs.txt", "a");
    fputs($fp, $rec_log);
    fclose($fp);

    return;
    }
    ?>




  • Michael Fesser

    #2
    Re: Question Regarding Session ID

    .oO(Douglas Pollock)
    [color=blue]
    >I'm new to session id variables. I'm trying to write records containing the
    >session id to a log file but the session id keeps disappearing. I'm using
    >session_regist er() because the site has register_global s = On (Hosted web
    >site Php Version 4.3.3).[/color]

    session_registe r() is deprecated, use the $_SESSION array instead. This
    way the script will also work on servers with register_global s = Off.
    [color=blue]
    >Can anyone explain what I'm doing wrong and why SID does not seem to have or
    >retain a value?[/color]

    SID is only set if the client rejects the session cookie.

    Micha

    Comment

    • Alvaro G. Vicario

      #3
      Re: Question Regarding Session ID

      *** Michael Fesser escribió/wrote (Thu, 03 Mar 2005 19:34:37 +0100):[color=blue]
      > SID is only set if the client rejects the session cookie.[/color]

      The OP is probably looking for session_id():

      string session_id ( [string id] )
      session_id() returns the session id for the current session.




      --
      -+ Álvaro G. Vicario - Burgos, Spain
      +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
      ++ Manda tus dudas al grupo, no a mi buzón
      -+ Send your questions to the group, not to my mailbox
      --

      Comment

      • NSpam

        #4
        Re: Question Regarding Session ID

        Douglas Pollock wrote:[color=blue]
        > I'm new to session id variables. I'm trying to write records containing the
        > session id to a log file but the session id keeps disappearing. I'm using
        > session_registe r() because the site has register_global s = On (Hosted web
        > site Php Version 4.3.3).
        >
        > If I work on my local Windows XP computer and I start up a browser window
        > the first printf statement
        > printf ("This is the SID = $szTmp01<br>"); results in:
        >
        > This is the SID =
        >
        > Which is blank. The second print statement gives.
        > This is the session_id = PHPSESSID=9ebb9 5e5a3a68662c5ff 32c2db358222
        >
        > which seems to work Ok.
        >
        > When I execute the script on the hosted web site the result is:
        > This is the SID =
        > This is the session_id =
        >
        > Can anyone explain what I'm doing wrong and why SID does not seem to have or
        > retain a value?
        >
        > Thanks,
        > Doug
        >
        > --------------------------------------------------
        >
        > <?php
        > session_start() ;
        > error_reporting (E_ALL);
        > $szTmp01 = '';
        >
        > $szTmp01 = SID;
        > printf ("This is the SID = $szTmp01<br>");
        >
        > if(!session_is_ registered("ses sion_id"))
        > {
        > session_registe r("session_id") ;
        > }
        >
        > $self_url = $_SERVER['PHP_SELF'];
        > if(IsSet($HTTP_ SESSION_VARS["session_id "]) &&
        > $HTTP_SESSION_V ARS["session_id "])
        > {
        > $session_id = $HTTP_SESSION_V ARS["session_id "];
        > $href = "$self_url?$szT mp01";
        > }
        > else
        > {
        > $session_id = SID;
        > session_registe r("session_id") ;
        > $href = $self_url;
        > }
        > printf ("This is the session_id = $session_id<br> ");
        > $MyVar = LogSession();
        > ?>
        >
        > <?php
        >
        > function LogSession()
        > {
        > global $session_id;
        > global $self_url;
        > global $HTTP_SESSION_V ARS;
        > global $href;
        >
        > if(!session_is_ registered('ses sion_id'))
        > {
        > $session_id = SID;
        > session_registe r('session_id') ;
        > }
        >
        > $dtime = date('r');
        >
        > $session_id = $HTTP_SESSION_V ARS["session_id "] ;
        >
        > $rec_log = "Date: $dtime | SID: $session_id \n";
        > $fp = fopen("SLog/logs.txt", "a");
        > fputs($fp, $rec_log);
        > fclose($fp);
        >
        > return;
        > }
        > ?>
        >
        >
        >
        >[/color]
        you don't need all this stuff, all you need to do is have an object that
        instantiates a session at the top of the code. In fact you don't even
        need to do that. the only essential thing in the above code is
        session_registe r which should be unconditional 'cos it will use an
        existing session or create one if a session don't exist.

        As to the rest of it, well be a control freak if you must, but why
        capture this information ?

        Comment

        Working...