Page 1 of 1
[SOLVED]variables N sessions
Posted: Mon Jan 02, 2006 1:24 am
by blacksnday
Im having a problem where if I have a variable for
a session, the session wont stick, but if
the session equals a variable it works fine.
Working:
Code: Select all
$_SESSION['site_template'] = $doselecttemplate;
Not Working:
Code: Select all
$_SESSION['site_template'] = $doselecttemplate;
$template = $_SESSION['site_template'];
Any ideas as to why?
Posted: Mon Jan 02, 2006 1:28 am
by mickd
what do you mean by "a variable for a session, the session wont stick"?
according to what you wrote,
all this should work...
Code: Select all
$_SESSION['site_template'] = $doselecttemplate;
$template = $_SESSION['site_template'];
echo ($doselecttemplate == $template) ? 'true' : 'false';
// that should return true.
EDIT: presuming session_start() is on.
Posted: Mon Jan 02, 2006 1:39 am
by blacksnday
mickd wrote:what do you mean by "a variable for a session, the session wont stick"?
What I mean is that the below works:
Code: Select all
if($doselecttemplate){
$_SESSION['site_template'] = $doselecttemplate;
}else if(!$_SESSION['site_template']){
$_SESSION['site_template'] = 'default';
}
include("templates/$_SESSION[site_template]/header.php");
but the following wont work
because the $template is not containing the
session value of the selection.
Code: Select all
if($doselecttemplate){
$_SESSION['site_template'] = $doselecttemplate;
$template = $_SESSION['site_template'];
}else if(!$_SESSION['site_template']){
$_SESSION['site_template'] = 'default';
$template = $_SESSION['site_template'];
}
include("templates/$template/header.php");
Posted: Mon Jan 02, 2006 2:09 am
by LazyJones
The only reason I can think of is that both if's fail and the $template doesn't have a value after that.
Posted: Mon Jan 02, 2006 3:25 am
by mickd
the only reason i can see would be that session_start() isnt declared for the second one. if i would of guessed between which wouldnt of worked, i would of chose the first...
Posted: Mon Jan 02, 2006 1:37 pm
by blacksnday
Ok, i figured out what I was doing wrong.
$template should be outside the if/else
Code: Select all
if($doselecttemplate){
$_SESSION['site_template'] = $doselecttemplate;
}else if (!$_SESSION['site_template']){
$_SESSION['site_template'] = 'default';
}
$template = $_SESSION['site_template'];
Posted: Mon Jan 02, 2006 2:51 pm
by mickd
ah, the scope of the variable, although i thought itll only give a notice and php would still work it accordingly? guess not.