I am trying to store some values via array in cookies using JavaScript, so that later I can call and use them in PHP variables. However, when I check the cookies, the array I stored has no name in the cookies, hence I cannot access them. Cookie name, appears as blank. This is how I am setting the cookie.
<script>
cook = {name: "john",email:"john@live.co.uk"};
mycook = JSON.stringify(cook);
document.cookie = mycook;
</script>
This is how it appears in inspect elements.
To call the values in PHP, I used the following code, but none of them work. I just get undefined array key error message. I used 2 variations to see which of them works to echo the cookie elements, but none of them work.
<?php
if(isset($_COOKIE)){
echo $_COOKIE['mycook.name'];
echo '<br>';
echo $_COOKIE['mycook->email'];
}
?>