Smarty Sesssion Variable Problem
I have four files.
1. index.php
2. index.tpl
3. file2.php
4. file2.tp
I am setting a ses开发者_运维技巧sion variable in index.php like this
$_SESSION['isVisible'] = true;
Then I am accessing this variable in file2.php like this
echo ($_SESSION['isVisible']);
but it doesn't work.
I am not starting session manually because I think session is already started by Smarty.
Any idea how can I access this variable?
Here's a little snippet to help you detecting if a session has been started or not,
Don't forget as well that a session initialized with session_start will only be available to pages within the directory tree of the page that first created it.
It could explain why Smarty uses another session_id than your current script...
function session_is_started() {
if (isset($_SESSION)) {
return true;
} else {
return false;
}
}
if (!session_is_started()){
session_start();
$_SESSION['isVisible'] = true;
}
echo $_SESSION['isVisible'];
精彩评论