PHP Session Variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NitinSawant
    Contributor
    • Oct 2007
    • 271

    PHP Session Variable

    Hello,
    I'm new to php,

    I'm storing temp variable in SESSION

    Code:
    $_SESSION['temp']='value';
    when i go from one php page to other php page, the session variable is accessible
    but when i go to the other page in a subdirectory.. the SESSION variable is not accesible..

    am i missing some php configuration?

    pls help

    regards,
    Nitin Sawant
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    but when i go to the other page in a subdirectory
    PHP does not have a GOTO command!

    Comment

    • NitinSawant
      Contributor
      • Oct 2007
      • 271

      #3
      Hello code green,
      I'm navigating from one page to another page in subdirectory
      suppose: current page 'index1.php'
      then in that page i write
      Code:
      <a href='std/index2.php'>go to subdirectory</a>
      then the session variable is lost when i navigate to 'index2.php' in std subdirectory..

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        is in that page the session restarted?

        Comment

        • NitinSawant
          Contributor
          • Oct 2007
          • 271

          #5
          nope, the session is not restarted..

          in index1.php page i wrote..
          Code:
          if (!isset($_SESSION)) {
              	session_start();
          }
          $_SESSION['temp']='value';
          and in the index2.php page in std directory i'm trying to retrieve the variable
          Code:
          $var=$_SESSION['temp'];

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by code green
            PHP does not have a GOTO command!
            It does now :P

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by NitinSawant
              nope, the session is not restarted..
              as I thought… you need to open a session first:
              Originally posted by php.net
              Note: […] Also note that you must start your session using session_start() before use of $_SESSION becomes available. […]

              Comment

              • NitinSawant
                Contributor
                • Oct 2007
                • 271

                #8
                But i'm starting the session on index page only
                Code:
                session_start();

                Comment

                • NitinSawant
                  Contributor
                  • Oct 2007
                  • 271

                  #9
                  well, what i was missing is adding 'session_start( );' on every page...

                  nevermind, i got it..

                  prob. solved


                  regards,
                  Nitin Sawant

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Originally posted by NitinSawant
                    well, what i was missing is adding 'session_start( );' on every page...

                    nevermind, i got it..

                    prob. solved


                    regards,
                    Nitin Sawant
                    That's exactly what Dormilich told you to do. :)

                    Comment

                    • dlite922
                      Recognized Expert Top Contributor
                      • Dec 2007
                      • 1586

                      #11
                      Originally posted by code green
                      PHP does not have a GOTO command!
                      Thanks for the laugh starting my Monday, it's been a sh*tty week.







                      Dan

                      Comment

                      Working...