Jump to content

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


Recommended Posts

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
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
session_start();

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

?>

 

sessionlesson02.php:

 

<?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
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~

In session sessionlesson.php and session03.php, replace this line

require('sessionlesson01.php');

With just

session_start();

 

Otherwise you're just overwriting your session variables with blank values. This is because the _POST variables will not be available on these pages, as the form is only submitted to sessionlesson02.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.