PHP session issue in Safari, Opera and IE

Through 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();
?>
+3
source share
1 answer

I was able to solve this problem. The answer lies in the P3P protocol.

I added

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

right in front

session_start()

Work!

0
source

Source: https://habr.com/ru/post/1757767/


All Articles