Hi Guys,
I'm trying to implement cookies into my website but it doesn't seem to recognise that I've set the cookie and gives me a new one everytime.
It always goes via the not set route?
I'm trying to implement cookies into my website but it doesn't seem to recognise that I've set the cookie and gives me a new one everytime.
PHP:
<?php
if(isset($_COOKIE['shoppingcart_id'])) {
echo "COOKIE IS SET";
}
else {
echo "COOKIE IS NOT SET";
//generate a random 10 character code
$shoppingcart_id = generateId();
//get the current date
$today = date("Y-m-d");
//get the users ip
$user_ip = $_SERVER['REMOTE_ADDR'];
//set the lifetime of the cookie
$expire = time()+(60*60*24*7);
//set the domain for which the cookie is valid
$dom = $_SERVER['SERVER_NAME'];
if($dom[0] == "w"){
//truncate the first three characters
$domain = substr($dom, 3);
}
else {
//add point
$domain = ".".$dom;
}
//finally send the cookie to the user agent
setcookie("shoppingcart_id", $shoppingcart_id, $expire, "/", $domain)
}
It always goes via the not set route?
Last edited: