dongzhuo1958 2012-03-10 01: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-10 01: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.

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

报告相同问题?

悬赏问题

  • ¥15 电脑出问题了,说是usbmom注册表没
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网