Session variables not working in PHP 5.0.4

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hussain123
    New Member
    • Jan 2007
    • 28

    Session variables not working in PHP 5.0.4

    Hi All,
    I have a web site which was hosted on m/c A and PHP version there was 4.4.3
    Now I have moved my website to m/c B and the PHP version is 5.0.4
    But now the problem is that the on the m/c B my session variables(HTTP session variables) used in the PHP code are not maintained across all the pages which is creating problem on my website.
    I have put the exact code in m/c B which was there in m/c A and was working perfectly.

    Am I missing here??
    I am not sure but do I ned to make any changes in my ini file on m/c B?

    Please Help.

    Regards,
    Hussain
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi Hussain.

    Could you show us how the code you use to create and use your session variables?

    Comment

    • hussain123
      New Member
      • Jan 2007
      • 28

      #3
      [code=php]
      <?
      //first page
      session_start() ;
      session_registe r('variable');

      $HTTP_SESSION_V ARS['variable']= value;
      ?>
      <html>
      <body>
      <a href="page2.php ">Page2</a>
      </body>
      </html>
      [/code]

      [code=php]
      <?
      //page 2
      $newvariable = $HTTP_SESSION_V ARS['variable'];

      echo $newvariable;
      ?>
      [/code]
      Thanks,
      Hussain
      Last edited by Atli; Nov 16 '07, 09:57 AM. Reason: Added [code] tags.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Ahh, I see.

        The $HTTP_SESSION_V ARS array is old and really should not be used.
        Use the $_SESSION super-global instead.

        I'm not really sure this will fix the problem, but it is a good place to start.

        Also, I recommend using <?php ... ?> instead of <? ... ?>. The short-tags version can cause problems when moving between servers.

        Consider this:
        [code=php]
        <?php
        //first page
        session_start() ;

        $_SESSION['variable'] = "Some value";
        ?>
        [/code]

        [code=php]
        <?php
        //page 2
        $newvariable = $_SESSION['variable'];

        echo $newvariable;
        ?>
        [/code]

        P.S.
        Please post all your code inside &#91;code] tags.

        &#91;code=ph p] PHP Code goes here &#91;/code]

        Thank you.

        Comment

        • LacrosseB0ss
          New Member
          • Oct 2006
          • 112

          #5
          I'm also having this problem. This post is mostly so I can subscribe and watch for answers here that may help me as well. Thanks!

          Comment

          Working...