Session not holding a value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shlomisderot
    New Member
    • Mar 2008
    • 4

    Session not holding a value

    Hello all,

    I'm not familiar with PHP session, my question is if session save the values when I brows to another page.
    It is possible to keep the session values when I go to other page (in the same domain)?

    In one script, let's say a.php I'm doing:
    [PHP]
    session_start() ;
    $_SESSION['fname'] = $row["fname"];
    $_SESSION['lname'] = $row["lname"];
    header("LOCATIO N: b.php")
    [/PHP]

    In b.php I'm doing:
    [PHP]
    print My name is: " .$_SESSION['fname']. " " . $_SESSION['lname'];
    [/PHP]

    I don't see the content of [PHP]$_SESSION['fname'] [/PHP] and [PHP]$_SESSION['lname'][/PHP]

    Thank you,
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    on b.php you need to initialise the session.

    On any page that uses sessions you need to use
    [php]
    session_start() ;
    [/php]
    Right before any other code.

    Regards.

    Comment

    • shlomisderot
      New Member
      • Mar 2008
      • 4

      #3
      Steel, I don't see the the session values...

      what I missing??

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by shlomisderot
        Steel, I don't see the the session values...

        what I missing??
        Well i dont know what your code is on b.php so i dont know.

        Comment

        • shlomisderot
          New Member
          • Mar 2008
          • 4

          #5
          Lets say:

          a.php contains:
          [PHP]
          <?php
          session_start() ;
          $_SESSION['username'] = 'shlomi';
          $_SESSION['password'] = 'elbaz';
          header("LOCATIO N: b.php");
          ?>
          [/PHP]

          b.php contains:
          [PHP]
          <?php
          session_start() ;
          print $_SESSION['username']. " " .$_SESSION['password'];
          ?>
          [/PHP]

          In the addressbar I see http://localhost/b.php but its show nothing

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            You must have made another error or typo because, when running your 2 scripts unchanged on my localhost, it runs fine, i.e. both values are printed.

            Ronald

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by ronverdonk
              You must have made another error or typo because, when running your 2 scripts unchanged on my localhost, it runs fine, i.e. both values are printed.

              Ronald
              As does mine.

              Regards.

              Comment

              • satas
                New Member
                • Nov 2007
                • 82

                #8
                Originally posted by shlomisderot
                Lets say:

                a.php contains:
                [PHP]
                <?php
                session_start() ;
                $_SESSION['username'] = 'shlomi';
                $_SESSION['password'] = 'elbaz';
                header("LOCATIO N: b.php");
                ?>
                [/PHP]

                b.php contains:
                [PHP]
                <?php
                session_start() ;
                print $_SESSION['username']. " " .$_SESSION['password'];
                ?>
                [/PHP]

                In the addressbar I see http://localhost/b.php but its show nothing
                Check session_save_pa th in your php.ini file. Make sure it has real path with write permissions.

                Comment

                • andrewteg
                  New Member
                  • Aug 2007
                  • 22

                  #9
                  Originally posted by satas
                  Check session_save_pa th in your php.ini file. Make sure it has real path with write permissions.
                  Also you can do a printout of phpinfo() and make sure session support is actually enabled. It'd be odd but it could happen.

                  Comment

                  Working...