开发者

PHP Session over 2 pages

i 开发者_C百科have the following code:

if (!isset($_SESSION)) {
ob_start();
}
$_SESSION['views'] = 1; // store session data
echo $_SESSION['views']; //retrieve data

i tried to break it up in 2 parts like this:

//Page 1
if (!isset($_SESSION)) {
ob_start();
}
$_SESSION['views'] = 1; // store session data

.

//page 2
echo $_SESSION['views']; //retrieve data

it echos nothing, what am I doing wrong?


as Gumbo mentioned, you need to call session_start() on every page you want to use the session..

You also mentioned you were getting the error: Warning: session_start(): Cannot send session cache limiter - headers already sent

This is due to data being output on the page before the session_start() is being called, you have to include this before anything is echo'd to the browser.


Make sure to call session_start on every page you want the session to be available. ob_start is not the session handler but the output buffer handler.


session_start() in 2 files before any output.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜