I want to send something to server with ajax GET
method and also using cookies, so I send my value to ajax, I need this value to update the current cookie value. In ajax file, I can't retrieve $_COOKIE['cookie_name']
, when I echo this, the result will be like this--> [] !
function card(action,value) {
if (value == "") {
document.getElementById('errmsgs').innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('errmsgs').innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","inc/pricing/pricing.php?act="+action+"&val="+value,true);
xmlhttp.send();
}
}
And the pricing page is:
<?php
require_once '../../connection.php';
require_once '../../func.php';
$what_is_action = $_REQUEST['act'];
$myCook = $_REQUEST['val'];
}
echo $full_cookie_value = $_COOKIE['mycookiename']; ----> output will be--> [] ---->but it must be something like this ---> {"wwde34":"1","effy33":"1","ssdfff":"1"}
if($what_is_action == 'delete'){
//delete_cook($myCook);
}
?>
Solved.
The problem was, when I trying to create the cookie, it was not in root, so in another folders It can't be accessible! so I added '/' at the last parameter of setcookie
for example: setcookie('a','b',time()+36666,'/')
this will create cookie in root and it can be accessible in other folders!