1 <?php 2 3 namespace Packback\Lti1p3\ImsStorage; 4 5 use Packback\Lti1p3\Interfaces\ICookie; 6 7 class ImsCookie implements ICookie 8 { 9 public function getCookie(string $name): ?string 10 { 11 if (isset($_COOKIE[$name])) { 12 return $_COOKIE[$name]; 13 } 14 // Look for backup cookie if same site is not supported by the user's browser. 15 if (isset($_COOKIE['LEGACY_'.$name])) { 16 return $_COOKIE['LEGACY_'.$name]; 17 } 18 19 return null; 20 } 21 22 public function setCookie(string $name, string $value, $exp = 3600, $options = []): void 23 { 24 $cookie_options = [ 25 'expires' => time() + $exp, 26 ]; 27 28 // SameSite none and secure will be required for tools to work inside iframes 29 $same_site_options = [ 30 'samesite' => 'None', 31 'secure' => true, 32 ]; 33 34 setcookie($name, $value, array_merge($cookie_options, $same_site_options, $options)); 35 36 // Set a second fallback cookie in the event that "SameSite" is not supported 37 setcookie('LEGACY_'.$name, $value, array_merge($cookie_options, $options)); 38 } 39 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body