How do I set Session Variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • christopher.j.just@gmail.com

    #1

    How do I set Session Variables

    I need to set the information being passed through the fields (23 of
    them) in the form into a session.

    Where do I start?

    Thanks,
    Chris

  • flamer die.spam@hotmail.com

    #2
    Re: How do I set Session Variables


    christopher.j.j ust@gmail.com wrote:
    I need to set the information being passed through the fields (23 of
    them) in the form into a session.
    >
    Where do I start?
    >
    Thanks,
    Chris
    you want the submitted data from a form into a session?

    //get the var out of the form
    $var1 = $_POST["var1"];

    //stick it into session
    $_SESSION["var2"] = $var1;

    Flamer.

    Comment

    • christopher.j.just@gmail.com

      #3
      Re: How do I set Session Variables

      I was using this which I believe accomplishes the same thing:

      session_start() ;
      $_SESSION['firstname'] = $_POST['firstname'];

      now, if I understand correctly, the element from the _POST array should
      have set the variable in the _SESSION array.

      So how the heck do I retrieve it on subsiquent pages? And what sort of
      settings do you need in PHP.INI for sessions to work?

      I've got a ton of inherited code/programs that are using global
      variables=on and I've got to turn that off as soon as I can and I'm
      starting at a dead stop at the moment.

      Any help is appreciated.

      Chris

      flamer die.spam@hotmai l.com wrote:
      christopher.j.j ust@gmail.com wrote:
      >
      I need to set the information being passed through the fields (23 of
      them) in the form into a session.

      Where do I start?

      Thanks,
      Chris
      >
      you want the submitted data from a form into a session?
      >
      //get the var out of the form
      $var1 = $_POST["var1"];
      >
      //stick it into session
      $_SESSION["var2"] = $var1;
      >
      Flamer.

      Comment

      • Jerry Stuckle

        #4
        Re: How do I set Session Variables

        christopher.j.j ust@gmail.com wrote:
        >
        flamer die.spam@hotmai l.com wrote:
        >
        >>christopher.j .just@gmail.com wrote:
        >>
        >>
        >>>I need to set the information being passed through the fields (23 of
        >>>them) in the form into a session.
        >>>
        >>>Where do I start?
        >>>
        >>>Thanks,
        >>>Chris
        >>
        >>you want the submitted data from a form into a session?
        >>
        >>//get the var out of the form
        >>$var1 = $_POST["var1"];
        >>
        >>//stick it into session
        >>$_SESSION["var2"] = $var1;
        >>
        >>Flamer.
        >
        >
        I was using this which I believe accomplishes the same thing:
        >
        session_start() ;
        $_SESSION['firstname'] = $_POST['firstname'];
        >
        now, if I understand correctly, the element from the _POST array should
        have set the variable in the _SESSION array.
        >
        So how the heck do I retrieve it on subsiquent pages? And what sort of
        settings do you need in PHP.INI for sessions to work?
        >
        I've got a ton of inherited code/programs that are using global
        variables=on and I've got to turn that off as soon as I can and I'm
        starting at a dead stop at the moment.
        >
        Any help is appreciated.
        >
        Chris
        (Top posting fixed)

        It's just as easy to get them out of the session:

        session_start() ;
        $firstname = $_SESSION['firstname'];

        The default settings in the php.ini file often work fine. Just look at
        the session entries. It's pretty well documented.

        The biggest problem I've seen is the session.save_pa th must point to a
        directory where the web server (if you're not using the CGI version of
        PHP) must have read/write access.

        P.S. Please don't top post. Thanks.

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

        Comment

        • christopher.j.just@gmail.com

          #5
          Re: How do I set Session Variables


          Jerry Stuckle wrote:
          christopher.j.j ust@gmail.com wrote:

          flamer die.spam@hotmai l.com wrote:
          >christopher.j. just@gmail.com wrote:
          >
          >
          >>I need to set the information being passed through the fields (23 of
          >>them) in the form into a session.
          >>
          >>Where do I start?
          >>
          >>Thanks,
          >>Chris
          >
          >you want the submitted data from a form into a session?
          >
          >//get the var out of the form
          >$var1 = $_POST["var1"];
          >
          >//stick it into session
          >$_SESSION["var2"] = $var1;
          >
          >Flamer.

          I was using this which I believe accomplishes the same thing:
          >
          session_start() ;
          $_SESSION['firstname'] = $_POST['firstname'];
          >
          now, if I understand correctly, the element from the _POST array should
          have set the variable in the _SESSION array.
          >
          So how the heck do I retrieve it on subsiquent pages? And what sort of
          settings do you need in PHP.INI for sessions to work?
          >
          I've got a ton of inherited code/programs that are using global
          variables=on and I've got to turn that off as soon as I can and I'm
          starting at a dead stop at the moment.
          >
          Any help is appreciated.
          >
          Chris
          >
          (Top posting fixed)
          >
          It's just as easy to get them out of the session:
          >
          session_start() ;
          $firstname = $_SESSION['firstname'];
          >
          The default settings in the php.ini file often work fine. Just look at
          the session entries. It's pretty well documented.
          >
          The biggest problem I've seen is the session.save_pa th must point to a
          directory where the web server (if you're not using the CGI version of
          PHP) must have read/write access.
          >
          P.S. Please don't top post. Thanks.
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===
          I've looked and the session.save_pa th is read/write accessable, but the
          majority of the session are blank so I'm not sure where I went wrong.
          I'm using just this basic form at the moment:

          <?php // text1.php
          session_start() ;
          $firstname = $_SESSION['firstname'];
          $lastname = $_SESSION['lastname'];
          $title = $_SESSION['title'];
          $institution = $_SESSION['institution'];
          $street = $_SESSION['street'];
          $city = $_SESSION['city'];

          // form
          echo <<<HTML
          <head><title>te xt1</title></head><body>
          <form method="post" action="text2.p hp">
          First Name: <input type="text" name="firstname " value=""/><br/>
          Last Name: <input type="text" name="lastname" value=""/><br/>
          Title: <input type="text" name="title" value=""/><br/>
          Institution: <input type="text" name="instituti on" value=""/><br/>
          Street: <input type="text" name="street" value=""/><br/>
          City: <input type="text" name="city" value=""/><br/>
          <input type="submit"/>
          </form></body></html>
          HTML;
          ?>

          and want to be able to pull the information on any of the subsiquent 3
          or 4 pages that people go through before completing it, but the session
          record is blank in the file.

          Comment

          • christopher.j.just@gmail.com

            #6
            Re: How do I set Session Variables


            christopher.j.j ust@gmail.com wrote:
            Jerry Stuckle wrote:
            christopher.j.j ust@gmail.com wrote:
            >
            flamer die.spam@hotmai l.com wrote:
            >
            >>christopher.j .just@gmail.com wrote:
            >>
            >>
            >>>I need to set the information being passed through the fields (23 of
            >>>them) in the form into a session.
            >>>
            >>>Where do I start?
            >>>
            >>>Thanks,
            >>>Chris
            >>
            >>you want the submitted data from a form into a session?
            >>
            >>//get the var out of the form
            >>$var1 = $_POST["var1"];
            >>
            >>//stick it into session
            >>$_SESSION["var2"] = $var1;
            >>
            >>Flamer.
            >
            >
            I was using this which I believe accomplishes the same thing:
            >
            session_start() ;
            $_SESSION['firstname'] = $_POST['firstname'];
            >
            now, if I understand correctly, the element from the _POST array should
            have set the variable in the _SESSION array.
            >
            So how the heck do I retrieve it on subsiquent pages? And what sort of
            settings do you need in PHP.INI for sessions to work?
            >
            I've got a ton of inherited code/programs that are using global
            variables=on and I've got to turn that off as soon as I can and I'm
            starting at a dead stop at the moment.
            >
            Any help is appreciated.
            >
            Chris
            (Top posting fixed)

            It's just as easy to get them out of the session:

            session_start() ;
            $firstname = $_SESSION['firstname'];

            The default settings in the php.ini file often work fine. Just look at
            the session entries. It's pretty well documented.

            The biggest problem I've seen is the session.save_pa th must point to a
            directory where the web server (if you're not using the CGI version of
            PHP) must have read/write access.

            P.S. Please don't top post. Thanks.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===
            >
            I've looked and the session.save_pa th is read/write accessable, but the
            majority of the session are blank so I'm not sure where I went wrong.
            I'm using just this basic form at the moment:
            >
            <?php // text1.php
            session_start() ;
            $firstname = $_SESSION['firstname'];
            $lastname = $_SESSION['lastname'];
            $title = $_SESSION['title'];
            $institution = $_SESSION['institution'];
            $street = $_SESSION['street'];
            $city = $_SESSION['city'];
            >
            // form
            echo <<<HTML
            <head><title>te xt1</title></head><body>
            <form method="post" action="text2.p hp">
            First Name: <input type="text" name="firstname " value=""/><br/>
            Last Name: <input type="text" name="lastname" value=""/><br/>
            Title: <input type="text" name="title" value=""/><br/>
            Institution: <input type="text" name="instituti on" value=""/><br/>
            Street: <input type="text" name="street" value=""/><br/>
            City: <input type="text" name="city" value=""/><br/>
            <input type="submit"/>
            </form></body></html>
            HTML;
            ?>
            >
            and want to be able to pull the information on any of the subsiquent 3
            or 4 pages that people go through before completing it, but the session
            record is blank in the file.

            OK, so I've got the records writing to the session folder and I can
            call them on the second page, now what I'm finding is that they won't
            persist - I've inserted an intermediary page in the sequence and what
            happens is that the information stored in the session file disappears.
            Here is the code:

            PAGE 1

            <?php // text1.php
            session_start() ;
            $_SESSION['SID'] = session_id();

            // form
            echo <<<HTML
            <head><title>te xt1</title></head><body>
            <form method="post" action="text2.p hp">
            First Name: <input type="text" name="firstname " value=""/><br/>
            Last Name: <input type="text" name="lastname" value=""/><br/>
            Title: <input type="text" name="title" value=""/><br/>
            Institution: <input type="text" name="instituti on" value=""/><br/>
            Street: <input type="text" name="street" value=""/><br/>
            City: <input type="text" name="city" value=""/><br/>
            <input type="submit"/>
            </form></body></html>
            HTML;
            ?>


            PAGE 2

            <?php // text2.php
            session_start() ;
            $sessionID = $_SESSION['SID'];
            // Do any checking on this here maybe?
            $_SESSION['firstname'] = $_POST['firstname'];
            $_SESSION['lastname'] = $_POST['lastname'];
            $_SESSION['title'] = $_POST['title'];
            $_SESSION['institution'] = $_POST['institution'];
            $_SESSION['street'] = $_POST['street'];
            $_SESSION['city'] = $_POST['city'];

            echo $_SESSION['firstname']; // should now work...
            ?>
            <html>
            <a href="text3.php ">Continue to next page</a>
            </html>


            PAGE 3

            <?php // text2.php
            session_start() ;
            $sessionID = $_SESSION['SID'];
            // Do any checking on this here maybe?

            $_SESSION['firstname'] = $_POST['firstname'];
            $_SESSION['lastname'] = $_POST['lastname'];
            $_SESSION['title'] = $_POST['title'];
            $_SESSION['institution'] = $_POST['institution'];
            $_SESSION['street'] = $_POST['street'];
            $_SESSION['city'] = $_POST['city'];

            echo $_SESSION['firstname']; // should now work...

            echo <<<HTML
            <head><title>te xt2</title></head><body>
            <form method="post" action="text3.p hp">
            text2: <input type="text" name="text2" value="" ><br/>
            <input type="submit"/><br/>
            </form><p>Return to <a href="text1.php ">text1</a>.</p>
            </body></html>
            HTML;

            echo $_POST['firstname'];

            ?>

            The session file goes from being populated with data to this:
            SID|s:32:"6ba62 4e9304bf5511a19 1a836a324c1b";f irstname|N;last name|N;title|N; institution|N;s treet|N;city|N;

            I'm thinking that I didn't make the data persistant, or didn't set
            something up on the link to the 3rd page correctly.

            I appreciate all the help I've gotten and if anyone has an explination
            about what I'm doing wrong it would be welcome.

            Thanks.

            Comment

            • Jerry Stuckle

              #7
              Re: How do I set Session Variables

              christopher.j.j ust@gmail.com wrote:
              christopher.j.j ust@gmail.com wrote:
              >
              >>Jerry Stuckle wrote:
              >>
              >>>christopher. j.just@gmail.co m wrote:
              >>>
              >>>>flamer die.spam@hotmai l.com wrote:
              >>>>
              >>>>
              >>>>>christophe r.j.just@gmail. com wrote:
              >>>>>
              >>>>>
              >>>>>
              >>>>>>I need to set the information being passed through the fields (23 of
              >>>>>>them) in the form into a session.
              >>>>>>
              >>>>>>Where do I start?
              >>>>>>
              >>>>>>Thanks,
              >>>>>>Chris
              >>>>>
              >>>>>you want the submitted data from a form into a session?
              >>>>>
              >>>>>//get the var out of the form
              >>>>>$var1 = $_POST["var1"];
              >>>>>
              >>>>>//stick it into session
              >>>>>$_SESSIO N["var2"] = $var1;
              >>>>>
              >>>>>Flamer.
              >>>>
              >>>>
              >I was using this which I believe accomplishes the same thing:
              >>
              >session_start( );
              >$_SESSION['firstname'] = $_POST['firstname'];
              >>
              >now, if I understand correctly, the element from the _POST array should
              >have set the variable in the _SESSION array.
              >>
              >So how the heck do I retrieve it on subsiquent pages? And what sort of
              >settings do you need in PHP.INI for sessions to work?
              >>
              >I've got a ton of inherited code/programs that are using global
              >variables=on and I've got to turn that off as soon as I can and I'm
              >starting at a dead stop at the moment.
              >>
              >Any help is appreciated.
              >>
              >Chris
              >>>
              >>>(Top posting fixed)
              >>>
              >>>It's just as easy to get them out of the session:
              >>>
              >> session_start() ;
              >> $firstname = $_SESSION['firstname'];
              >>>
              >>>The default settings in the php.ini file often work fine. Just look at
              >>>the session entries. It's pretty well documented.
              >>>
              >>>The biggest problem I've seen is the session.save_pa th must point to a
              >>>directory where the web server (if you're not using the CGI version of
              >>>PHP) must have read/write access.
              >>>
              >>>P.S. Please don't top post. Thanks.
              >>>
              >>>--
              >>>============ ======
              >>>Remove the "x" from my email address
              >>>Jerry Stuckle
              >>>JDS Computer Training Corp.
              >>>jstucklex@at tglobal.net
              >>>============ ======
              >>
              >>I've looked and the session.save_pa th is read/write accessable, but the
              >>majority of the session are blank so I'm not sure where I went wrong.
              >>I'm using just this basic form at the moment:
              >>
              ><?php // text1.php
              >>session_start ();
              >>$firstname = $_SESSION['firstname'];
              >>$lastname = $_SESSION['lastname'];
              >>$title = $_SESSION['title'];
              >>$institutio n = $_SESSION['institution'];
              >>$street = $_SESSION['street'];
              >>$city = $_SESSION['city'];
              >>
              >>// form
              >>echo <<<HTML
              >><head><title> text1</title></head><body>
              >><form method="post" action="text2.p hp">
              >>First Name: <input type="text" name="firstname " value=""/><br/>
              >>Last Name: <input type="text" name="lastname" value=""/><br/>
              >>Title: <input type="text" name="title" value=""/><br/>
              >>Institution : <input type="text" name="instituti on" value=""/><br/>
              >>Street: <input type="text" name="street" value=""/><br/>
              >>City: <input type="text" name="city" value=""/><br/>
              >><input type="submit"/>
              >></form></body></html>
              >>HTML;
              >>?>
              >>
              >>and want to be able to pull the information on any of the subsiquent 3
              >>or 4 pages that people go through before completing it, but the session
              >>record is blank in the file.
              >
              >
              >
              OK, so I've got the records writing to the session folder and I can
              call them on the second page, now what I'm finding is that they won't
              persist - I've inserted an intermediary page in the sequence and what
              happens is that the information stored in the session file disappears.
              Here is the code:
              >
              PAGE 1
              >
              <?php // text1.php
              session_start() ;
              $_SESSION['SID'] = session_id();
              >
              // form
              echo <<<HTML
              <head><title>te xt1</title></head><body>
              <form method="post" action="text2.p hp">
              First Name: <input type="text" name="firstname " value=""/><br/>
              Last Name: <input type="text" name="lastname" value=""/><br/>
              Title: <input type="text" name="title" value=""/><br/>
              Institution: <input type="text" name="instituti on" value=""/><br/>
              Street: <input type="text" name="street" value=""/><br/>
              City: <input type="text" name="city" value=""/><br/>
              <input type="submit"/>
              </form></body></html>
              HTML;
              ?>
              >
              >
              PAGE 2
              >
              <?php // text2.php
              session_start() ;
              $sessionID = $_SESSION['SID'];
              // Do any checking on this here maybe?
              $_SESSION['firstname'] = $_POST['firstname'];
              $_SESSION['lastname'] = $_POST['lastname'];
              $_SESSION['title'] = $_POST['title'];
              $_SESSION['institution'] = $_POST['institution'];
              $_SESSION['street'] = $_POST['street'];
              $_SESSION['city'] = $_POST['city'];
              >
              echo $_SESSION['firstname']; // should now work...
              ?>
              <html>
              <a href="text3.php ">Continue to next page</a>
              </html>
              >
              >
              PAGE 3
              >
              <?php // text2.php
              session_start() ;
              $sessionID = $_SESSION['SID'];
              No, not necessary.
              // Do any checking on this here maybe?
              >
              $_SESSION['firstname'] = $_POST['firstname'];
              $_SESSION['lastname'] = $_POST['lastname'];
              $_SESSION['title'] = $_POST['title'];
              $_SESSION['institution'] = $_POST['institution'];
              $_SESSION['street'] = $_POST['street'];
              $_SESSION['city'] = $_POST['city'];
              >
              You just wiped out your $_SESSION values here. You didn't post these
              values to this page, did you?
              echo $_SESSION['firstname']; // should now work...
              >
              echo <<<HTML
              <head><title>te xt2</title></head><body>
              <form method="post" action="text3.p hp">
              text2: <input type="text" name="text2" value="" ><br/>
              <input type="submit"/><br/>
              </form><p>Return to <a href="text1.php ">text1</a>.</p>
              </body></html>
              HTML;
              >
              echo $_POST['firstname'];
              >
              ?>
              >
              The session file goes from being populated with data to this:
              SID|s:32:"6ba62 4e9304bf5511a19 1a836a324c1b";f irstname|N;last name|N;title|N; institution|N;s treet|N;city|N;
              >
              I'm thinking that I didn't make the data persistant, or didn't set
              something up on the link to the 3rd page correctly.
              >
              I appreciate all the help I've gotten and if anyone has an explination
              about what I'm doing wrong it would be welcome.
              >
              Thanks.
              >
              Hope this helps.

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

              Comment

              Working...