当前位置: 动力学知识库 > 问答 > 编程问答 >

php - session does not work with mod-rewrited urls?

问题描述:

I have this page www.exmaple.com/username which is rewritten url, but the sessions does not work there.

That is, when I echo, it does not show the value, but all the other pages that have not been re-written are working!

<?php session_start();

echo $_SESSION['user_id'];

?>

Is there something that I'm missing?

网友答案:

Does this rewrite involve a change of domain or subdomain in the URL? Cookies are, by default, accessible only to the same subdomain they were set on... and session identifiers are maintained by cookies.

网友答案:

Sessions are not affected by mod_rewrite, but you need to prepend every page with session_start().

网友答案:

You must call session_start() to read the session or $_SESSION will not be populated.

分享给朋友:
您可能感兴趣的文章:
随机阅读: