dongzhuo1958 2012-03-09 17:25
浏览 33
已采纳

为什么$ _SESSION和$ _COOKIE表现不一样?

I've done some testing with $_SESSION and $_COOKIE because I they weren't working as I expected. I'd like to know why these lines of code behave differently.

$_SESSION[1] = 'foo';          // Does not work because of the integer
$_COOKIE[1] = 'bar';           // Works

$_SESSION['foo bar'] = 'foo';   // Works with the space
$_COOKIE['foo bar'] = 'bar';    // Does not work

I would have thought $_SESSION and $_COOKIE would be identical, other than being server side vs. client side. Are there any other differences between the two?

  • 写回答

1条回答 默认 最新

  • dtyyrt4545 2012-03-09 17:33
    关注

    The answers on this question address some of the issues involved, but the short answer is that there are different restrictions depending on whether it's a session or a cookie. Sessions are restricted space-wise by different php.ini settings, cookies don't allow spaces in keys, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部