I have been working on a backend login and admin page for my site. What is happening is I'am able to log in to the site using sessions and get into the admin page. I then navigate away from the admin page to add or edit an entry or refresh the admin page and the session seems to disappear and my code moves me back to my login page again.
I can't seem to figure out whats going. I'm starting each page with the Session_Start(); function and i'm echoing out the session variable on every page to make sure its there. The session variable I'am passing is the $_SESSION['name'] which is the first name of the person logged in.
Here is the code I'm working with for the Admin Page:
<?php
session_start();
if (isset($_SESSION['name']))
{
?>
<title>Beacon Admin Page</title>
<script type="text/javascript">
var GB_ROOT_DIR = "greybox/";
</script>
<script type="text/javascript" src="greybox/AJS.js"></script>
<script type="text/javascript" src="greybox/AJS_fx.js"></script>
<script type="text/javascript" src="greybox/gb_scripts.js"></script>
<link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" />
<link href="/Beacon/New_Site/adminstyle.css" rel="stylesheet" type="text/css">
<li><a href="<?php echo $_SERVER['PHP_SELF'] ?>?caseid=home">Home </a></li>
<li><a href="<?php session_destroy(); echo "http://www.newportharbor.com/Beacon/New_Site/login.php"; ?>">Logout</a></li>
<div id ="time">
<?php
$today = date("F j, Y");
?>
Welcome: <strong><?php echo $_SESSION['name']; ?></strong><br>
Today's Date: <strong><?php echo $today; ?></strong>
</div>
<?php
function check_status($status)
{
if ($status == "Pending")
{
echo "<tr bgcolor = '808080'";
}
else
{
echo "<tr>";
}
}
// Contents of Admin Page are displayed
}// End If Statement
// Else redirect user to login
else
{
echo "You need to login <a href='login.php'>Click Here To Go Back</a>";
}
?>