0

I have this webpage where I want to set a cookie, and if the cookie is set it redirects you to another page. I use to code below, and it all works fine in google chrome, but it does not in safari for some reason. Do you know why this is and/or do you have a solution for it?

//current url: https://thisdomain.com    
setcookie("cookie1", "isset", time() + (10 * 365 * 24 * 60 * 60), "/", "thisdomain.com", true, true);
sleep(1);
if (isset($_COOKIE["cookie1"])) {
header("Location: https://nextdomain.com", true, 301);
exit();
}
header("Location: https://www.thisdomain.com", true, 301);

Thank you in advance :)

Chris
  • 85
  • 1
  • 4
  • 16
  • Reload the page and you'll see. Cookies are only set after they've been set and not during the same operation of setting and checking if it's set. Show us what's on the other page. Plus, the cookie is set in your computer and the other browser already had it set. – Funk Forty Niner Oct 24 '19 at 12:15
  • @FunkFortyNiner The code makes the page reload until the cookie is set and then it goes to the next domain. This works fine on chrome, but not in safari – Chris Oct 24 '19 at 12:19
  • Oh so this is cross-domain related, that could make all the difference. – Funk Forty Niner Oct 24 '19 at 12:20
  • @FunkFortyNiner Oh, wait, let me just edit that – Chris Oct 24 '19 at 12:22
  • 1
    There's an answer here. https://stackoverflow.com/a/486569 – dgtal Oct 24 '19 at 12:35
  • @dgtal okay, so just to make sure that I have understood this correctly: there is no way to make this work? – Chris Oct 24 '19 at 13:21
  • Some workarounds worked for a while, but stopped working with the latest versions. Maybe there are other working ways now, but will probably stop working sooner or later 'cause it's not possible by design. So i would say there is no way to make this work. – dgtal Oct 24 '19 at 13:25

0 Answers0