I'm trying to set a PHP cookie via AJAX. I'm putting one variable ("listingID") into the cookie name. If I hard code the name (eg. "cMapPin220") the cookie sets correctly, however I require a variable in the name to identify it.
AJAX:
function myFunc(listingID){
$.ajax({
url: 'cookie.php',
type: 'POST',
data: {listingID:listingID},
dataType: 'html'
}).success(function(data){
$('.div66').html(data);
}).fail(function(jqXHR, errMsg) {
alert("Request failed: " + errMsg);
});
}
In "cookie.php"
This doesn't work:
<?php
$cookieName = 'cMapPin' . $_POST['listingID'];
setcookie($cookieName, '1', time()+30);
?>
This works:
<?php
$cookieName = 'cMapPin220';
setcookie($cookieName, '1', time()+30);
?>