PHP session_id( ) null

John Lee picture John Lee · Dec 21, 2010 · Viewed 14.1k times · Source

I am having some difficulty with sessions.

On my local MAMP test server, if I do:

session_start( ); echo session_id( );

I get a nice looking session id.

If However, I the same thing on my web server, all I can get back from session_id is 'null'. Testing the return from session_start( ) and using sessions everything is working, but session_id( ) $SID and $PHPSESSID are all null.

Is this hidden on purpose for added security? I want to be able to allow flash to make changes to a shopping cart through PHP calls and have the cart (which is stored in the session) reflected using the browser.

Answer

user471679 picture user471679 · Dec 21, 2010

Make sure the return value of session_start() is TRUE.

Make sure you are calling session_start() before your script outputs anything to the browser.

Check that apache has write access to the session path. Mine is /tmp