PHP Session Problem in Safari, Opera, and IE
Over SSL. Works in Chrome/Firefox but shows an empty value for sessionTestVariable for Opera/Safari/IE:
<? // https://mydomain.com/setSession.php
session_cache_limiter( 'nocache' );
session_set_cookie_params("899", "/", ".mydomain.com");
session_start();
unset($_SESSION['sessionTestVariable']);
// Set sessionTestVariable
$_SESSION['sessionTestVariable'] = "some string";
header("Cache-Control: no-cache, must-revalidate, post-check=3600, pre-check=3600"); // CacheBusting
header("Location: http://mydomain2.com/testSession.php");
exit; // this *should* fix the problem but does not
?>
开发者_高级运维
////////////
<? // http://mydomain2.com/testSession.php
echo "Testing to see if we can trigger the session from mydomain.com";
echo "<script type=\"text/javascript\" src=\"https://mydomain.com/triggerCookie.php\">";
?>
////////////
<? // https://mydomain.com/triggerCookie.php
session_cache_limiter( 'nocache' );
session_set_cookie_params("899", "/", ".mydomain.com");
session_start();
// Set sessionTestVariable
echo "alert('session: " . $_SESSION['sessionTestVariable'] . "');";
session_destroy();
?>
I was able to solve this problem. The answer lies in a protocol called P3P.
I added
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
right before
session_start()
Works!
精彩评论