Page 1 of 1

session variable not setting

Posted: Fri Nov 14, 2008 5:20 pm
by petethepirate
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.'');
}

Re: session variable not setting

Posted: Sat Nov 15, 2008 3:45 am
by JAB Creations
Use the following to see what data is currently in your session...

Code: Select all

<?php
print_r($_SESSION);
?>

Re: session variable not setting

Posted: Sat Nov 15, 2008 3:52 am
by alex.barylski
First thing I would do is add a echo like so:

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.'');
  }
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.