开发者

php sessions problem

i have such problem: when i'm starting session in php there are no errors, session_start return true, but no data stored in session, session file is empty and session_id always different. what reason?

ini_开发者_如何学运维set('session.use_cookies', '0' );
ini_set('session.use_trans_sid', '1' );    
session_start();
if (isset($_SESSION['test']))
echo($_SESSION['test']);
$_SESSION['test'] = 'test';
echo("<a href='test.php?".SID."'>refr</a>");


Check you have write permission to session.save_path. Check the log files.

Enable cookies on the browser you're testing it on. Use session_start() on every page you wish to access the session variables.

If you're manually adding the session_id to the url, clear your cookies first. There are also security settings that may block you resuming sessions in that manner.


Are you adding content to the session? Other than the session ID, the session will always be blank upon creation- until you create/set some $_SESSION variables.

Note also, the $_SESSION id will always be different between browsing 'sessions'.

See here:

If id is specified, it will replace the current session id. session_id() needs to be called before session_start() for that purpose.

http://php.net/manual/en/function.session-id.php


You're using the transparent sid feature, yet you're appending it manually, but in the wrong way.

I recommend this instead:

ini_set('session.use_cookies', '0');
ini_set('session.use_trans_sid', '0');
session_start();
if (isset($_SESSION['test']))
    echo($_SESSION['test']);
$_SESSION['test'] = 'test';
echo("<a href='test.php?PHPSESSID=".session_id()."'>refr</a>");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜