I am trying to do this:
setCookie('visitor', array(0 => 'one', 1 => 'two'), time()+3600, COOKIEPATH, COOKIE_DOMAIN, false);
But I am unable to get it work. The php reference explains “$value as string[optional]” which (as far as my understanding goes) should accept an array of string as argument. Please help me achieve something similar to this or correct me if my understanding of the php reference ( string[optional] ) is wrong.
Here is the setcookie function declaration:
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
use
serialize(array(0 => 'one', 1 => 'two'))instead.Use
unserialize()when retrieving the array again.And no: If the php manual says that the functions wants a string… Then they mean a string. Not an array of strings.
Maybe you are fooled by the [optional]? The square brackets don’t mean anything. The whole “[optional]” thing just means that the function can be called without this parameter.