Skip to content Skip to sidebar Skip to footer

Cookies Not Saving On Android Mobile

I'm using this javascript function to setup a cookie on my site that will show a div wile the cookie isn't setup. function accept_cookies(){ days=365; // number of days to keep

Solution 1:

You can use the php method "setcookie" to create a Set-Cookie header, that will set a cookie on the client side.

http://php.net/manual/en/function.setcookie.php

Processes that happens in the server side (php) are much more reliable than on the client side.

Usage example with php and ajax jquery library:

<a href="#" onClick="ajaxPost()">active</a>

function ajaxPost(){
   $.post("action.php",{action: "setTheCookie"}, function(result){
    // Do something
   }
}

action.php

checkAction();
function checkAction(){
   if($_POST["action"] == "setTheCookie")
     setCookie("cookie name", "cookie value", time() + (86400 * 30), "/");
   exit();
}

Post a Comment for "Cookies Not Saving On Android Mobile"