简体   繁体   中英

Why PHP Session Destroyed?

I have this php code,

<?php

session_start();
Print_r($_SESSION);
$_SESSION['value'] = 1;
Print_r($_SESSION);

?>

Why it Prints following, everytime when I refreshes the page..

Array
(
)
Array
(
    [value] => 1
)

It should Print,

Array
(
    [value] => 1
)
Array
(
    [value] => 1
)

I am using lighttpd as http Server on Fedora 14.

I read that running chown -R root:lighttpd /var/lib/php/ fixed the problem for others that were having the same issue.

Source:
http://masdeni.com/archives/6-Lighttpd-+-PHP-Session-Problem.html

I would test to see if session_start() returns true (session started), for example:

$is_session_started = session_start();

If $is_session_started == false , then you have 1/2 your answer right there. The other 1/2 will lie in figuring out why it is not starting. Per @Ryan above, check your session ini settings.

If you are using cookies for storing the Session ID, make sure that you call session_start() before printing/echoing/returning any other values to the browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM