doulei3488 2011-04-11 06:31
浏览 34
已采纳

PHP:$ _SESSION永远不会被设置,但$ _POST是?

[@the downvote and idiot remarks, that's not cool to beat up on people. I rechecked the documentation and coursenotes for 3 whole days before even asking the question - . Closing this to prevent a chorus of idiots piling on with useless and factually incorrect comments, as James did. Thanks to Charles and Brent B for being very helpful. This turns out not to be a Safari issue so I removed those tags.]


$_SESSION is not getting set in Safari, and hence my multipage form breaks. $_POST, $_REQUEST do get set (but obviously disappear on subsequent pages). Versions are PHP: 5.3.1, Safari 5.

Help! It is not an issue with any of the following, I checked them all, and I read all the other related questions:

  • session_start() works. SID/PHPSESSID is preserved across pages.
  • session.use_cookies = 1, session.use_only_cookies = 1
  • I checked php.ini and believe it to be ok
  • I did configure Safari to accept All cookies (for now). No difference.
  • I can manually set $_SESSION['debug'] and that does get preserved across pages (and the session file is correctly written out). Unless I do that, $_SESSION never gets defined.

I don't have time to debug this nonsense, so which of the following last-minute workarounds is the least ugly? (this is a programming assignment, not production code) According to course notes , $_SESSION is supposed to merge $_POST, $_REQUEST, $_GET, session and globals right?

  1. manually do $_SESSION = array_merge($_SESSION,$_POST); [this works]
  2. use hidden form to re-post $_POST on subsequent forms
  3. other?

(On a wider note, should PHP simply be considered broken on Safari (5)?)

  • 写回答

1条回答 默认 最新

  • dongzine3782 2011-04-11 07:31
    关注

    $_SESSION does NOT merge other super global arrays, it is it's own array. $_REQUEST is a merge of $_POST and $_GET, but that's about it. From what you describe, $_SESSION is working properly. Read the official manual. http://www.php.net/manual/en/language.variables.superglobals.php

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看