I am having a Session's issue. The code below does everything it is supposed to do except when the code on page one executes and redirects to the code on page 2 the Session ends and redirects to the index_ForMike.php page (as if the SESSION variables are no longer recognized). I copied and pasted these pieces of code from two other pages and the Sessions work fine and have absolutely no issues. The only difference in PHP code is that elsewhere on the pages below I am echoing some variables onto the page, but that is the only difference.
I am relatively new to using sessions. Am I missing something? Is there something I can look for to help resolve this issue?
Any thoughts would be greatly appreciated. Thanks in advance!
Code on one page:
<?php
session_start();
if ( $_SESSION['id'] == null || $_SESSION['id'] < 1 )
{
header( "Location: ../../index_ForMike.php" );
exit;
} elseif ($_SESSION['level'] < 5) {
header( "Location: ../../index_ForMike.php" );
exit;
}
require_once( "DB.php" );
require_once( "../../include.php" );
$sql = "SELECT * FROM agents WHERE agentId = '$_SESSION[id]'";
$row = $db->getRow($sql);
$firstName = $row['firstName'];
$lastName = $row['lastName'];
$id = $_GET['id'];
$announcements = "SELECT * FROM announcements WHERE id='$id'";
$announcementsRow = $db->getRow($announcements);
$date = $announcementsRow['date'];
$announcement = stripslashes(strip_tags($announcementsRow['announcement']));
if ($_POST['_submit_check']) {
process_form();
}
function process_form() {
global $db;
$id = $_POST['id'];
$date = $_POST['date'];
$announcement = nl2br(addslashes($_POST['announcement'])) ;
$sqlUpdate = "UPDATE announcements SET date = ?, announcement = ? WHERE id = $id";
$db->query($sqlUpdate, array($date, $announcement));
print "<script>window.location='UpdateAnnouncement_Success.php'</script>";
}
?>
The 'UpdateAnnouncement_Success.php' page includes the following PHP code:
<?php
session_start();
if ( $_SESSION['id'] == null || $_SESSION['id'] < 1 )
{
header( "Location: ../../index_ForMike.php" );
exit;
} elseif ($_SESSION['level'] < 5) {
header( "Location: ../../index_ForMike.php" );
exit;
}
require_once( "DB.php" );
require_once( "../../include.php" );
$sql = "SELECT * FROM agents WHERE agentId = '$_SESSION[id]'";
$row = $db->getRow($sql);
$firstName = $row['firstName'];
$lastName = $row['lastName'];
?>