greatwhitenorth98
Technical User
Yep, I'm a Newbie - with session problems. The code below, while relatively simple, does not keep the session variable to the next page. In fact, when looking at the temp file where the session ids are kept, there is one session generated by loading the first page, another when going from the first to the second and a third one going back to the first page. Regardless (and probably due to), the $_SESSION variable is not kept and echoed to the screen.
Please, someone tell me what is going on!? I'm going bananas here! I've looked throughout the forum and applied the ideas that I have found - to no avail.
Thanks a heap!
--------------------------
index.htm
--------------------------
<?php
session_start();
$_SESSION['user'] = "Hubert";
echo "(IDX) Session user: " .$_SESSION['user']. "<br>";
if(isset($_POST['session_check'])) {
header("Location: session_check.htm");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Session test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']?>" method="post">
<br><br>
<input type="submit" name="session_check" value="Check Session variables">
</form>
</body>
</html>
--------------------------
session_check.htm
--------------------------
<?php
session_start();
if(isset($_POST['home'])) {
unset($_SESSION['user']);
header("Location: index.htm");
}
echo "(SC) Session user: " .$_SESSION['user']. "<br>";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Session test - Page 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']?>" method="post">
<br><br>
<input type="submit" name="home" value="Home">
</form>
</body>
-------------------------
Please, someone tell me what is going on!? I'm going bananas here! I've looked throughout the forum and applied the ideas that I have found - to no avail.
Thanks a heap!
--------------------------
index.htm
--------------------------
<?php
session_start();
$_SESSION['user'] = "Hubert";
echo "(IDX) Session user: " .$_SESSION['user']. "<br>";
if(isset($_POST['session_check'])) {
header("Location: session_check.htm");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Session test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']?>" method="post">
<br><br>
<input type="submit" name="session_check" value="Check Session variables">
</form>
</body>
</html>
--------------------------
session_check.htm
--------------------------
<?php
session_start();
if(isset($_POST['home'])) {
unset($_SESSION['user']);
header("Location: index.htm");
}
echo "(SC) Session user: " .$_SESSION['user']. "<br>";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Session test - Page 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']?>" method="post">
<br><br>
<input type="submit" name="home" value="Home">
</form>
</body>
-------------------------