开发者

PHP: Sessions across includes

I am needing to use sessions for my php page, so, on my index.php page, I add session_start(); right after the opening php tag.

开发者_如何转开发But, this page has some includes, inside of which have other includes. So, deeper down, when I want to call a $_SESSION var, it is not working.

How can I access a session var even deep down into .inc files?


session_start() works across includes. Your problem must be somewhere else:

#file1.php
var_dump($_SESSION['somevar']);

#base.php
session_start();
include 'file1.php';
//the contents of $_SESSION['somevar'] will be dumped
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜