Cookie special characters
My app needs to set cookies for specific paths in the app. For example (in php):
setcookie(*cookie_name*,*value*,*date*,"/subpath/subpath/unique_name");
setcookie(*cookie_name*,*value*,*date*,"/subpath/subpath/another unique name");
Oddly enough, the first setcookie works great. In the second case, no error is raised and when I view my cookies in Firefox the cookie has the correct values. However, I cannot access it in my code. I believe whitespace is causing problems, but I haven't found any documentation or specs on how to encode cookie paths.
Has anyone encountered this problem before? Does anyone know how to handle special characters in cookie paths?
I don't see any problem with spaces in cookies. Maybe you should check how you read your worth ...
My reader program:
function ReadCookie(name)
{
name += '=';
var parts = document.cookie.split(/;\s*/);
for (var i = 0; i < parts.length; i++)
{
var part = parts[i];
if (part.indexOf(name) == 0)
return part.substring(name.length)
}
return null;
}
Obviously the only thing you have to code is the comma.
source to share
There is no access to the web server atm. Have you tried one of them?
setcookie(*cookie_name*,*value*,*date*, "/subpath/subpath/another unique name/");
setcookie(*cookie_name*,*value*,*date*, urlencode("/subpath/subpath/another unique name"));
setcookie(*cookie_name*,*value*,*date*, rawurlencode("/subpath/subpath/another unique name"));
I believe different browsers and webservers may treat them differently. Hopefully you don't need to use spaces in the url.
source to share