Forum Moderators: coopster
function GetCartId() {
if(isset($_COOKIE["cartId"])) {
return $_COOKIE["cartId"];
} else {
//generate a cookie id
$cookieID = "";
$possible = "abcdefghijklmnopqrstuvwxyz0123456789";
$n = 0;
// add random characters to $password until $length is reached
while ($n < 15) {
// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
// we don't want this character if it's already in the password
if (!strstr($cookieID, $char)) {
$cookieID .= $char;
$n++;
}
}
$path = '/subdomains/cvperfect/httpdocs/';
$hostname = '#*$!';
setcookie("cartId", $cookieID, time() + 3600, $path, $hostname);
return $_COOKIE["cartId"];
}
}
Can anyone see any problems with the code? Would I be better off using a session?
regards
holmags
to this
setcookie("cartId", $cookieID, time() + 3600);
If this works then you know it has something to do with your path and hostname. I'm not an expert on Cookies [php.net] or anything, but this is what i would try first to isolate the problem.
eelix