Problem with session variables
Posted: Mon Mar 24, 2003 4:08 pm
I don't know enough about sessions to know what the problem is. I just encountered it while reading a tutorial on sessions.
Here is my first page (where the user will enter his name):
page1.html:
<html>
<body>
<FORM METHOD="POST" ACTION="page2.php">
Enter your Name: <input type="text" name="name">
<input type="SUBMIT" value="Submit">
</FORM>
</body>
</html>
Here is second page where the form data goes:
page2.php:
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
echo "<strong>Step 2 - Register Session </strong><br />";
// Get the user's input from the form
$name = $_POST['name'];
// Create a new Session Value
session_register('name');
// Register the input with the value
$_SESSION['name'] = $name;
// Display the sssion information:
?>
Welcome to my website <strong><? echo $_SESSION['name']; ?></strong>!<br />
Let's see what happens on the <a href="page3.php">next page.</a><br /><br />
Here is third page:
page3.php:
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
?>
<strong>Step 3 - Test Session Part II </strong><br />
Hey <strong><? echo $_SESSION['name']; ?></strong> Everything is still working!<br /><br />
<strong>Pick an option:</strong><br />
Let's delete this session value now. <a href="page4.php">Click Here.</a><br />
Let's destroy this session. <a href="page5.php">Click Here.</a><br /><br />
The problem is on page 3 where it is supposed to print the session variable name. But it just leaves that out, like we never even inserted that into the code.
Any help with this?
Thanks a bunch for all help and advice provided.
Here is my first page (where the user will enter his name):
page1.html:
<html>
<body>
<FORM METHOD="POST" ACTION="page2.php">
Enter your Name: <input type="text" name="name">
<input type="SUBMIT" value="Submit">
</FORM>
</body>
</html>
Here is second page where the form data goes:
page2.php:
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
echo "<strong>Step 2 - Register Session </strong><br />";
// Get the user's input from the form
$name = $_POST['name'];
// Create a new Session Value
session_register('name');
// Register the input with the value
$_SESSION['name'] = $name;
// Display the sssion information:
?>
Welcome to my website <strong><? echo $_SESSION['name']; ?></strong>!<br />
Let's see what happens on the <a href="page3.php">next page.</a><br /><br />
Here is third page:
page3.php:
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
?>
<strong>Step 3 - Test Session Part II </strong><br />
Hey <strong><? echo $_SESSION['name']; ?></strong> Everything is still working!<br /><br />
<strong>Pick an option:</strong><br />
Let's delete this session value now. <a href="page4.php">Click Here.</a><br />
Let's destroy this session. <a href="page5.php">Click Here.</a><br /><br />
The problem is on page 3 where it is supposed to print the session variable name. But it just leaves that out, like we never even inserted that into the code.
Any help with this?
Thanks a bunch for all help and advice provided.