Losing Session Variables

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

    Losing Session Variables

    I place a session_start () within php tags at the top of one of my pages.
    Then I get a value and placed it in a php variable called $clientid.

    After that, I register the session variable using: session_registe r
    ("clientid") ; So far o.k. Two pages later, I'm trying to get the value of
    that session variable using:

    $viewerclientid = $_SESSION['client_id']; The problem that I'm having is
    that while this works in some computers, other users

    are having problems. It seems that they lose the value of this session
    variable. Both users, the ones that run this successfully and the ones that
    don't seem to be using

    IE 6 as a browser on the same version of windows (XP).

    Thanks.


  • HappyHourHotSpots.com

    #2
    Re: Losing Session Variables

    I had the same problem when writing my site. I found that it worked
    best by putting <?php session_start() ; ?> all by itself on the top of
    every page (the very first line before anything else). After that,
    everything seemed to work out much better.

    Example:
    <?php session_start() ; ?>

    <?php
    // Other PHP Code Here
    ?>

    Comment

    • Joshua Beall

      #3
      Re: Losing Session Variables

      "paddy_nyr" <mpprpp@yahoo.c om> wrote in message
      news:39tn1dF609 p2eU1@individua l.net...[color=blue]
      >I place a session_start () within php tags at the top of one of my pages.
      > Then I get a value and placed it in a php variable called $clientid.
      >
      > After that, I register the session variable using: session_registe r
      > ("clientid") ; So far o.k. Two pages later, I'm trying to get the value of
      > that session variable using:[/color]

      I would recommend against using session_registe r - see warning about
      register_global s here: http://php.net/session_register

      Instead you should simply put things in $_SESSION. If you don't want to
      type out $_SESSION['client_id'] each time you can still do

      $client_id = &$_SESSION['client_id'];

      Changes to $client_id will be recorded in the session record.
      [color=blue]
      >
      > $viewerclientid = $_SESSION['client_id']; The problem that I'm having is
      > that while this works in some computers, other users
      > are having problems. It seems that they lose the value of this session
      > variable. Both users, the ones that run this successfully and the ones
      > that
      > don't seem to be using
      > IE 6 as a browser on the same version of windows (XP).[/color]

      Are you using redirects anywhere? You should called session_write_c lose()
      beforehand, as in:

      session_write_c lose();
      header('Locatio n: http://mysite.com/somepage.php');
      exit(0);

      If you do not write out the session before redirecting the browser, there is
      a chance that the second page will start up, and read in the session record,
      before the first page has finished shutting down and writing the session
      record, causing lost session data. I've experienced this before.

      HTH,
      -Josh


      Comment

      • Joshua Beall

        #4
        Re: Losing Session Variables

        "paddy_nyr" <mpprpp@yahoo.c om> wrote in message
        news:39tn1dF609 p2eU1@individua l.net...[color=blue]
        >I place a session_start () within php tags at the top of one of my pages.
        > Then I get a value and placed it in a php variable called $clientid.[/color]

        Wait, at the top of *one* of your pages? You know you have to have it at
        the top of all your pages, right?


        Comment

        • pete1952
          New Member
          • Mar 2006
          • 1

          #5
          re session

          Thanks so much for your entry. It worked for me and I've been looking all day for the answer. I use Dreamweaver 8 and it did not have a clue.
          Thanks again! Pete Smith


          Originally posted by HappyHourHotSpo ts.com
          I had the same problem when writing my site. I found that it worked
          best by putting <?php session_start() ; ?> all by itself on the top of
          every page (the very first line before anything else). After that,
          everything seemed to work out much better.

          Example:
          <?php session_start() ; ?>

          <?php
          // Other PHP Code Here
          ?>

          Comment

          Working...