DanielTech
Programmer
I am trying to make login page work using sessions. The problem is that once I have initialized the session and I try to retrieve it from another page (page3.php in my code) I don't get anything. When I try to print out the session is blank, Does anyone have any idea why? here is my code:
////////////////////////////////////////////////
//// login.html
///////////////////////////////////////////////
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>
<FORM METHOD="POST" ACTION="page2.php">
Enter your Name: <input type="text" name="name">
<input type="SUBMIT" value="Submit">
</FORM>
</body>
</html>
///////////////////////////////////////////////
//// page2.php
//////////////////////////////////////////
<html>
<head>
<title>Login</title>
</head>
<body>
<?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'];
// Register session key 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/>
</body>
</html>
//////////////////////////////////////////////////////////////
/// page3.php
////////////////////////////////////////////////////////////
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
?>
<strong>Step 3 - Test Session Part II </strong><br />
Print session: <strong><? echo $_SESSION['name']; ?></strong><br/><br/>
</body>
</html>
////////////////////////////////////////////////
//// login.html
///////////////////////////////////////////////
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
session_start();
header("Cache-control: private"); // IE 6 Fix.
?>
<FORM METHOD="POST" ACTION="page2.php">
Enter your Name: <input type="text" name="name">
<input type="SUBMIT" value="Submit">
</FORM>
</body>
</html>
///////////////////////////////////////////////
//// page2.php
//////////////////////////////////////////
<html>
<head>
<title>Login</title>
</head>
<body>
<?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'];
// Register session key 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/>
</body>
</html>
//////////////////////////////////////////////////////////////
/// page3.php
////////////////////////////////////////////////////////////
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
?>
<strong>Step 3 - Test Session Part II </strong><br />
Print session: <strong><? echo $_SESSION['name']; ?></strong><br/><br/>
</body>
</html>