I am trying to set a cookie as part of a login script but the cookies never seem to set. I've checked the code with copious debug points and the st cookie is called and setcookie responds true but on inspection no cookies exist. I've double checked by using chrome to look at my cookies - there are none there for this app.
The step before this checks for headers already sent so I know that is not the problem.
<?php
// ...
public function set_cookie($cookie,$value,$time=0){
$cookieCONF = core::get()->factory()->get_config('cookie',array('path'=>'/','domain'=>'.'));
core::get()->debug()->log("COOKIE[{$cookie}]", $value, FALSE, 7);
if($time!==0){
$time= time()+$time;
}
if(!is_array($value)){
setcookie($cookie, $value, $time, $cookieCONF['path'], $cookieCONF['domain']);
}else{
foreach($value as $val=>$ue){
core::get()->debug()->log("{$cookie}[{$val}]", $ue, FALSE, 8);
if(setcookie("{$cookie}[{$val}]", $ue, $time, $cookieCONF['path'], $cookieCONF['domain'])){
core::get()->debug()->log('COOKIE RESULT',"SET {$cookie}[{$val}]={$ue}", FALSE, 8);
}else{
core::get()->debug()->log('COOKIE RESULT',"NOPE {$cookie}[{$val}]={$ue}", FALSE, 8);
}
}
}
}
echoing out the values the function being called is:
setcookie("user[k]", "295f<SNIP>98f2", $time, "/~username/folder/", "localhost");
(Except with the path information for the user and folder in actual use).
This is the debug line that shows that setcookie() is returning true (success).
[15] => Array
(
[message] => COOKIE RESULT
[ref] => SET user[k]=295f<SNIP>98f2
)
So unless there is a limit to numeric keys only that I am unaware of I cannot see why these cookies refuse to set.
What have I done wrong?
Edit
Cookies can take non-numeric keys.
Changing the code to
setcookie("user[k]", "295f<SNIP>98f2", $time);
resulted in cookies being set. However, that set to too wide a scope.