PHP setcookie to resemble ASP.Net Cookie subkeys
ASP.Net has the concept of using 'subkeys' in cookies. i.e. You can write a cookie with
Respo开发者_开发知识库nse.Cookies("userInfo")("userName") = "patrick"
Response.Cookies("userInfo")("lastVisit") = "today"
This would create a cookie which looks like
Name: userInfo
Value: userName=patrick:lastVisit=today
Is there a native method in PHP to read/write cookies like the above one?
I need to read/write a cookie in PHP which can be read by ASP.Net with subkeys
To write such a cookie:
$userInfo = array(
'userName' => 'patrick'
,'lastLogin' => 'today');
$userInfo = str_replace('&', ':', http_build_query($userInfo));
setrawcookie('userInfo', $userInfo);
to parse the cookie back into an array:
$userInfo = parse_str(str_replace(':', '&', $_COOKIE['userInfo'));
setrawcookie()
is a solution for that.
精彩评论