Why is a PHP session broken?

I have this php code,

<?php session_start(); Print_r($_SESSION); $_SESSION['value'] = 1; Print_r($_SESSION); ?> 

Why does this print the following, every time I refresh the page.

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

He must print

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

I use lighttpd as an http server on Fedora 14.

+4
source share
2 answers

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

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

+4
source

I would check if session_start() returns true (session started), for example:

 $is_session_started = session_start(); 

If $is_session_started == false , then you have 1/2 the answer to it. The other 1/2 will lie in figuring out why it doesn't start. Per @Ryan above, check your session settings.

If you use cookies to store the session ID, make sure you call session_start() before printing / echoing / returning any other values ​​to the browser.

+1
source

All Articles