Why PHP Session Destroyed?

我的梦境 提交于 2019-12-07 07:11:25

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/14079769/why-php-session-destroyed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!