Session variables across multiple pages

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

    Session variables across multiple pages

    Hi,

    I'm busy fiddling with sessions under PHP5, and very quickly learned
    what I would have found out even sooner in the PHP manual - declaring
    your session variable on page1.php makes it available on page2.php
    (assuming that's the next page you load) but doesn't then make it
    available on page3.php unless you respecify it on page2.php. I'm sure
    there's a very good reason for it, and I know I can get around it by
    using a database and the session ID, but I would really like to know:
    why? I've already searched, but can't find any more information on the
    issue.

    Thanks,
    John Heathcote

  • Captain Paralytic

    #2
    Re: Session variables across multiple pages

    On 26 Jul, 12:58, John H <john.heathc... @gmail.comwrote :
    Hi,
    >
    I'm busy fiddling with sessions under PHP5, and very quickly learned
    what I would have found out even sooner in the PHP manual - declaring
    your session variable on page1.php makes it available on page2.php
    (assuming that's the next page you load) but doesn't then make it
    available on page3.php unless you respecify it on page2.php. I'm sure
    there's a very good reason for it, and I know I can get around it by
    using a database and the session ID, but I would really like to know:
    why? I've already searched, but can't find any more information on the
    issue.
    >
    Thanks,
    John Heathcote
    You've got to be careful about your language when dealing with php and
    other such languages, when considering web pages.

    You have said: "declaring your session variable on page1.php".

    Now do you mean "on the web page that is displaed as a result of
    executing page1.php", or "in the script file page1.php".

    This is important because there does not need to be a one-to-one
    relationship between a .php file and a web page.

    One php file may display zero, one or more than one web page.
    Alternatively a web page may be made up of output from more than one
    php script file.

    Comment

    • gosha bine

      #3
      Re: Session variables across multiple pages

      On 26.07.2007 13:58 John H wrote:
      Hi,
      >
      I'm busy fiddling with sessions under PHP5, and very quickly learned
      what I would have found out even sooner in the PHP manual - declaring
      your session variable on page1.php makes it available on page2.php
      (assuming that's the next page you load) but doesn't then make it
      available on page3.php unless you respecify it on page2.php.
      This is not true. Once set, a "session variable" (more strictly, a key
      in the $_SESSION array) is automatically available to all pages sharing
      the same session.


      --
      gosha bine

      makrell ~ http://www.tagarga.com/blok/makrell
      php done right ;) http://code.google.com/p/pihipi

      Comment

      • Jerry Stuckle

        #4
        Re: Session variables across multiple pages

        John H wrote:
        Hi,
        >
        I'm busy fiddling with sessions under PHP5, and very quickly learned
        what I would have found out even sooner in the PHP manual - declaring
        your session variable on page1.php makes it available on page2.php
        (assuming that's the next page you load) but doesn't then make it
        available on page3.php unless you respecify it on page2.php. I'm sure
        there's a very good reason for it, and I know I can get around it by
        using a database and the session ID, but I would really like to know:
        why? I've already searched, but can't find any more information on the
        issue.
        >
        Thanks,
        John Heathcote
        >
        It should be available on every page you load - as long as you call
        session_start() at the beginning of the page.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • John  H

          #5
          Re: Session variables across multiple pages

          On Jul 26, 3:26 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          John H wrote:
          Hi,
          >
          I'm busy fiddling with sessions under PHP5, and very quickly learned
          what I would have found out even sooner in the PHP manual - declaring
          your session variable on page1.php makes it available on page2.php
          (assuming that's the next page you load) but doesn't then make it
          available on page3.php unless you respecify it on page2.php. I'm sure
          there's a very good reason for it, and I know I can get around it by
          using a database and the session ID, but I would really like to know:
          why? I've already searched, but can't find any more information on the
          issue.
          >
          Thanks,
          John Heathcote
          >
          It should be available on every page you load - as long as you call
          session_start() at the beginning of the page.
          Thanks to everyone for their help - I eventually found the problem on
          my side with session_start() not being declared on a few of the pages
          - I've now got a require() function on my template to put in the
          appropriate headers, including session_start() . Also, thanks to
          Captain Paralytic - I described the problem thus to simplify matters,
          but yes, I was talking about a single html page at a time with php
          script inside it. Your point, however, is well taken.


          Comment

          Working...