Reputation: 21
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
Upvotes: 2
Views: 4367
Reputation: 4592
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.
Upvotes: 2