Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post

    HELP! Sessions won't work on more than 2 pages at a time!

    How can I make this session code show the SAME results on sessionlesson02.php AND session03.php using the SAME session variables as defined in sessionlesson01.php? I need this as I plan to make a printable view page of a customer's receipt before they buy something, but in order to do that, I need to be able to use the same session variable more than 1 time on more than 2 pages all at one time.

    sessionlesson.php:

    PHP Code:
    <?php
    require('sessionlesson01.php');
    ?>
    <html>
    <head><title>Session Lesson</title></head>
    <body>
    <form name="sesstest" id="sesstest" action="sessionlesson02.php" method="POST">
    <center>
    <tr>
    <td>Color: </td>
    <td><input type="text" name="color01" id="color01" size="30"></td>
    <br>
    <td>Number: </td>
    <td><input type="text" name="number01" id="number01" size="30"></td>
    </tr>
    <br><br>
    <input type="submit" value="Submit">
    </center>
    </form>
    </body>
    </html>
    sessionlesson01.php:

    PHP Code:
    <?php
    session_start
    ();

    $_SESSION['color'] = $_POST['color01'];
    $_SESSION['number'] = $_POST['number01'];

    ?>
    sessionlesson02.php:

    PHP Code:
    <?php
    require('sessionlesson01.php');
    ?><html>
    <head><title>Session Lesson</title></head>
    <body>
    <form name="sesstest2" id="sesstest2" action="sessionlesson03.php" method="POST">
    <center>
    <?php
    echo "Favorite Color: ".$_SESSION['color']."<br>\n";
    echo 
    "Favorite Number: ".$_SESSION['number']."<br>\n";
    ?>
    <br>
    <input type="submit" value="Submit">
    </center>
    </form>
    </body>
    </html>
    session03.php:

    PHP Code:
    <?php
    require('sessionlesson01.php');
    ?><html>
    <head><title>Session Lesson</title></head>
    <body>
    <form name="sesstest3" id="sesstest3">
    <center>
    <?php
    echo "Favorite Color: ".$_SESSION['color']."<br>\n";
    echo 
    "Favorite Number: ".$_SESSION['number']."<br>\n";
    ?>
    </center>
    </form>
    </body>
    </html>
    Thanks!

    ShadowIce~
    Last edited by ShadowIce; 01-16-2010 at 03:38 PM.

  • #2
    New Coder
    Join Date
    Nov 2009
    Posts
    62
    Thanks
    9
    Thanked 0 Times in 0 Posts
    The proper way to achieve what you want is store the variables in a session in your sessionlesson2.php like:
    PHP Code:
    $_SESSION['color'] = $_POST['color'];
    $_SESSION['number'] = $_POST['number']; 
    your sessionlesson01.php should look like :
    PHP Code:
    <?php
    session_start
    ();
    ?>
    ,then just call the session variables when you need them on any page:
    PHP Code:
    echo $_SESSION['color'];
    echo 
    $_SESSION['number']; 

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Yep you're basically changing the values to the post values every page load
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •