I have a problem with session. I have 3 php pages login, home and edit. When i login session is created successfully and goes to home. In home I have a link which goes to edit. But when i go to edit the session is unset. I tried to echo session value in both pages. It successfully shows session value in home but not in edit. What might be the problem? Please help.
login.php
if($countStudent == 1){
$_SESSION['stuName']= $username;
header("location:studenthome.php");
home.php
<?php
error_reporting(0);
session_start();
if(!isset($_SESSION['stuName'])) {
echo "Click here to <a href=\"index.php\">Re-LogIn</a>";
}
else if(isset($_POST['logout']))
{
unset($_SESSION['stuName']);
header('Location: index.php');
}
else if(isset($_POST['edit']))
{
header('Location: edit.php');
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="container">
<?php
if (isset($_SESSION['stuName'])) {
?>
<form id="studenthome" action="studenthome.php" method="post"/>
<div id="menubar">
<input type="submit" name="logout" value="Logout" />
<input type="submit" name="edit" value="Edit Profile" />
</form>
</div>
<?php
}
?>
</body>
</html>
upto this everything is working fine.
edit.php
session_start();
if(!isset($_SESSION['stuName'])) {
echo "Click here to <a href=\"index.php\">Re-LogIn</a>";
}