开发者

best practices in naming session variables

I was used to naming my session variables the "normal" way, kinda like when I want to keep track of user details, I name them:

  • $_SESSION['username']
  • $_SESSION['email']
  • $_SESSION['id']

I am worried that they may be in conflict with other session data when I am br开发者_开发知识库owsing sites in the same browser, or will there not be any conflict at all(once I tried to simultaneously run two of my projects with the same session variables, residing in the same server, and obviously, things got real messy).


All of the session data is stored on the server. All the browser has is a cookie that references the session on the server. There can't be naming conflicts for this reason, and also because Cookies naming scope is domain based.


Consider setting them in a subarray related to your application:

$_SESSION['myapp']['username']
$_SESSION['myapp']['id']

That should significantly help avoid conflicts.

EDIT: I misread your question, Luca Matteis has your answer. My solution above would be to avoid your multiple apps on the same domain session conflict.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜