Pull value from PHP Cookie Array -
i doing modifications site built in asp. however, mods in php site being moved on language.
when user signs in, assigned cookies lkie so:
("mycook")("id")=23 ("mycook")("pref")="html" ("mycook")("job")="janitor"
now in asp, these can referenced as:
request.cookies("mycook")("pref")
which respond "html"
is there similar syntax php aware of?
this doesn't seem work:
echo $_cookie['mycook']['pref']; echo $_cookie["mycook"]["pref"];
i saw solution uses each -> , , can see how work. seems bit of overkill (to loop through values print 1 looking for) , wondering if had ideas?
thanks in advance help.
in example, cookies stored following string in "mycook" cookie:
["mycook"]=>string(27) "pref=html&job=janitor&id=23"
so access need echo $_cookie['mycook']
translate url encoded string more useful.
parse_str($_cookie['mycook'], $mycook); echo $mycook['pref'];
if don't need have second level cookies, assigning as:
response.cookies("id")=23 response.cookies("pref")="html" response.cookies("job")="janitor"
will allow access cookies in php just:
echo $_cookie['pref'];
Comments
Post a Comment