I have a session variable thats not setting no matter what I do. All other variables set fine, the variable $event does have a value, before and after. Ive verified this with debug info. Other session variables set. I have session_start(); at the beginning of every page. I cant figure out why it wont set. If you can see what Im doing wrong please let me know, thanks.
<?php
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT'].'/libf.php');
$event = $_POST['myevent'];
$user = $_SESSION['userid'];
if ($event[0] != " ")
{
if ($_SESSION['currentpage'] == "")
{
$_SESSION['myevent'] = $event;
$page = '/users/'.$user.'';
echo 'variable is blank';
exit();
header( 'Location: ' .$page.'');
} else
{
echo '<p>event equals '.$event.'</p>'."\n";
$_SESSION['event'] = $event;
$_SESSION['myevent'] = "";
$page = '/users/'.$_SESSION['currentpage'].'';
echo ''.gettype($event).'';
echo '<p>variable is not blank, session event equals *'.$_SESSION['event'].'* event equals *'.$event.'*'</p>'."\n";
exit();
header( 'Location: ' .$page.'');
}
session variable not setting
Moderator: General Moderators
-
petethepirate
- Forum Newbie
- Posts: 10
- Joined: Sat Oct 04, 2008 5:33 pm
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: session variable not setting
Use the following to see what data is currently in your session...
Code: Select all
<?php
print_r($_SESSION);
?>-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: session variable not setting
First thing I would do is add a echo like so:
Make sure that echo is sent to the screen for starters...technically there is nothin wrong that I can see. What is $event is it an array or object? Or a string? If it's the former you might need to serialize() the object before assigning it to $_SESSION variables.
Code: Select all
if($event[0] != " "){
if ($_SESSION['currentpage'] == ""){
echo 'Is this code even being evaluated???'; // NOTE: Your two previous conditions -- are they being met?
$_SESSION['myevent'] = $event;
$page = '/users/'.$user.'';
echo 'variable is blank';
exit();
header( 'Location: ' .$page.'');
}