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 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目