PHP: $_SESSION never getting set, but $_POST is ?

2019-08-18 17:19发布

问题:

[@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:

$_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