I am using the Set-Cookie function ..it works fine in chrome and firefox.
It sets the cookie and I can see it in firebug.
But for some reason it is not setting the cookie in I.E
Can anyone verify if my syntax is correct or if I am doing something wrong?
function generateSession($cookieName="wic_secure_sess", $idTag="", $numChars=32, $expireSeconds=0, $path=null, $domain=null, $secure=2) {
if (!isset($_COOKIE[$cookieName])) {
$sessId = $idTag;
for ($i=0; $i<$numChars; $i++) {
srand((double)microtime()*1000000);
$randomType=rand(1, 3);
srand((double)microtime()*1000000);
switch ($randomType) {
case 1:
$sessId.=chr(rand(65, 90));
break;
case 2:
$sessId.=chr(rand(97, 122));
break;
case 3:
$sessId.=rand(0, 9);
break;
}
}
$expires = str_replace('+0000', 'GMT', gmdate('r', strtotime('+30 days')));
if ($expireSeconds != 0) {
$expireSeconds = time()+$expireSeconds;
}
if (livecheck() || stagecheck()) {
header( "Set-Cookie:". $cookieName."=".$sessId."; expires=".$expires."; path=".$path.";HttpOnly;secure;");
}
else {
header( "Set-Cookie:". $cookieName."=".$sessId."; expires=".$expires."; path=".$path.";HttpOnly");
}
} else {
$sessId = $_COOKIE[$cookieName];
}
return $sessId;
}
?>
I dont want to use setcookie() because i am running php4 version since php4 does not support httponly in the setcookie() function
EDIT: the php setcookie() function works perfectly fine in IE. When i use header() thats creating the problem.
setcookie($cookieName, $sessId, $expireSeconds, $path, $domain, $secure);
Here is the call to my function:
generateSession( "my_sess", "", 20, 14400, "/");