2

I'm facing an issue that in my website payment gateway(migs) using as iframe, in Safari browser the default cookie block is "From third parties and advertisers", so getting error "cookie not enabled error" from gateway(migs) response. I need to detect such cookie block using php/javascript for showing this cookie block issue.

--

EDITED:

I'm facing the same issue, iOS7 is preventing my LinkedIn social login button to work since "Block cookies from third parties" is disabled. In lack of a solution I'd like to know how to check if they are enabled with Javascript or Javascript+PHP. @lisovaccaro

lisovaccaro
  • 32,502
  • 98
  • 258
  • 410
user2193674
  • 21
  • 1
  • 3
  • Did you find an alternative fro detecting third party cookies ,am also in the same boat http://stackoverflow.com/questions/22411226/javascript-solution-to-detect-if-third-party-cookie-is-disabled – sajanyamaha Mar 18 '14 at 07:08

1 Answers1

2

I guess one way of doing it is to have a script on another domain (not a subdomain, according to definition but I haven't tested this) that simply sets a cookie, and then the script can return JSONP so you can use it with javascript on another domain. So something like:

PHP ( cookie.php )

<?php
header("Content-type: application/javascript");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

if(isset($_GET["set"])){ //first run here
    setcookie("cookie_test","cookies",time()+3600);
    //redirect to self after setting cookie so we don't have to call script twice
    header('Location: cookies.php?&callback='.@$_GET["callback"]);
    die(); //death
}
//once redirected should go here
$cookie_set=array("cookies"=>isset($_COOKIE["cookie_test"]));
echo @$_GET["callback"]. "(" . json_encode($cookie_set) . ")";

Javascript/Jquery

//callback=? for jquery to know it's jsonp. &set so the script sets first
$.getJSON("http://another.domain.com/cookies.php?callback=?&set")
    .done(function(data){
       if(data.cookies){
          //third party cookies are enabled
       } else {
          //third party cookies probably disabled
       }
    })

Demo. Tested it out on Safari on Mac.

mfirdaus
  • 4,574
  • 1
  • 25
  • 26
  • I really haven't tried it yet it but I see why it should work. Thanks – lisovaccaro Jun 03 '14 at 17:45
  • @lisovaccaro thanks. Also not sure if you've seen this. I was testing with safari by disabling and enabling again, and somehow safari still kept that cookie after disabling. Looking it up more, safari has a weird "block third party cookie" behaviour. Once a user visits the domain apparently safari will allow the cookies from then on. Some potential workarounds here http://stackoverflow.com/questions/9930671/safari-3rd-party-cookie-iframe-trick-no-longer-working – mfirdaus Jun 04 '14 at 06:19
  • Thank you. I've been able to work around it in iOS7 but it was an overkill so I ended up disabling it for all devices. I'll probably use this code so I ask iOS users to enable third party cookies. – lisovaccaro Jun 04 '14 at 14:41