PHP:包含的会话

Nic*_*ard 0 php session include

我需要为我的php页面使用会话,因此,在我的index.php页面上,我添加了session_start(); 在打开php标签之后.

但是,这个页面有一些包含,其中包含其他内容.所以,更深层次的,当我想调用$ _SESSION var时,它无效.

如何访问会话变量甚至深入到.inc文件?

Pim*_*ger 7

session_start()适用于包含.您的问题必须在其他地方:

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

#base.php
session_start();
include 'file1.php';
//the contents of $_SESSION['somevar'] will be dumped
Run Code Online (Sandbox Code Playgroud)