session variable problem

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

    session variable problem

    i have been having difficulty with session variables - i seem to be able to
    set them, but when i wish to have another page update them, they remain as
    they were. this makes them utterly useless to me.
    does anyone know why i am having this problem and what i can do to rectify
    it?



  • E-Star

    #2
    Re: session variable problem

    In article <3f3f4f80$0$236 00$5a62ac22@fre enews.iinet.net .au>, Sticks
    <strat11@hotmai l.com> wrote:
    [color=blue]
    > i have been having difficulty with session variables - i seem to be able to
    > set them, but when i wish to have another page update them, they remain as
    > they were. this makes them utterly useless to me.
    > does anyone know why i am having this problem and what i can do to rectify
    > it?[/color]

    On each page you must call session_start()

    Are you doing that?

    Comment

    • Sticks

      #3
      Re: session variable problem

      yes, session_start() is called at the top of every page
      perhaps i should try and be a little more clear:
      the variables are set with no problems, and i can call them from other pages
      where i declare session_start() . however, if i want those pages to update
      the variable, the variable remains the way it was initially set.

      for eg:

      page1.php:

      <?php
      session_start() ;
      $test = "hello";
      $_SESSION["test"] = $test;
      header("Locatio n: page2.php");
      ?>

      page2.php

      <?php
      session_start() ;
      echo "original value: ".$_SESSION["test"]."<br />\n";
      $_SESSION["test"] = "world";
      echo "new value: ".$_SESSION["test"]."<br />\n";
      ?>

      page2.php would output:
      original value: hello
      new value: hello

      much to my chagrin.
      please note - this code has NOT been tested. this is just stuff i knocked up
      to show how much i know about performing this operation and the errors i
      have been experiencing by utilising it in exactly this fashion. therefore,
      if i am missing a semicolon or a bracket or suchlike from the above example,
      this is not what is causing the problem.

      any help would be greatly appreciated.
      sticks


      Comment

      • Jochen Buennagel

        #4
        Re: session variable problem

        Sticks wrote:[color=blue]
        > please note - this code has NOT been tested. this is just stuff i knocked up
        > to show how much i know about performing this operation and the errors i
        > have been experiencing by utilising it in exactly this fashion. therefore,
        > if i am missing a semicolon or a bracket or suchlike from the above example,
        > this is not what is causing the problem.[/color]

        I clipboarded the code to the appropriate files and it works fine.
        [color=blue]
        > page2.php would output:
        > original value: hello
        > new value: hello[/color]

        The output I get is:
        original value: hello
        new value: world

        So your problem must be somewhere else.

        Jochen

        --
        /**
        * @author Jochen Buennagel <zang at buennagel dot com>
        */

        Comment

        Working...