开发者

$_SESSION is not retaining data - PHP

I've used session vars multiple times in the past, with no problems, but now it's got me...

The $_SESSION var I am setting is becoming unset every time the PHP script is fired, although it is setting ok for one开发者_高级运维 variable at a time.

if (!isset($_SESSION['badList'])) {
    print 'not set - again?';
    $_SESSION['badList'][0] = $lineNum;
}
else
{
    $_SESSION['badList'][count($_SESSION)] = $lineNum;
}

Here 'not set - again?' fires every time I perform the suitable action, i.e. PHP is not able to find the initial session var. The session cache seems to clear completely when a script is run, which sort of ruins the point of sessions.

What can I do? Many thanks.


Ensure you've called session_start(), /etc/php.ini (or system equivalent) has a session.save_path set (ususally /var/lib/php/session/) and that directory is writable by your web server (on Linux it should be drwxrwx---) and that your disk is not full. If your sessions are being written to a remote store (database, memcached etc) make sure you can connect to that with the credentials your app uses (if applicable).

edit: also ensure you are calling session_write_close() at the end of your request - if you don't then the session data may not be written

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜