开发者

Smarty Sesssion Variable Problem

开发者 https://www.devze.com 2023-02-15 21:39 出处:网络
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

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'];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号