从参数php获取cookie内容

从参数php获取cookie内容,php,cookies,Php,Cookies,我在片场有这个饼干 $id = "1" $password = "test"; $cookie_name = "megamitch_server_status"; $cookie_time = (3600 * 24 * 30); // 30 days setcookie ($cookie_name, 'usr='.$id.'&hash='.$password, time() + $cookie_time); 如何在cookie名称“megamit

我在片场有这个饼干

    $id = "1"
    $password = "test";
    $cookie_name = "megamitch_server_status";
    $cookie_time = (3600 * 24 * 30); // 30 days
    setcookie ($cookie_name, 'usr='.$id.'&hash='.$password, time() + $cookie_time);
如何在cookie名称“megamitch_server_status”中获取usr的值


任何帮助、想法和建议都将不胜感激。谢谢大家!

这应该适合您:

(这里我只是用来提取数据)

或者,如果您愿意,您可以这样存储您的cookie:

setcookie ($cookie_name . "[usr]", $id, time() + $cookie_time);
setcookie ($cookie_name . "[hash]", $password, time() + $cookie_time);
echo $_COOKIE["megamitch_server_status"]["usr"];
echo $_COOKIE["megamitch_server_status"]["hash"];
然后您可以像这样访问它们:

setcookie ($cookie_name . "[usr]", $id, time() + $cookie_time);
setcookie ($cookie_name . "[hash]", $password, time() + $cookie_time);
echo $_COOKIE["megamitch_server_status"]["usr"];
echo $_COOKIE["megamitch_server_status"]["hash"];

你试过什么吗?到目前为止,我试过的是echo$_COOKIE['megamitch_server_status']['usr'];但遗憾的是,它不起作用。为什么在用户中,我得到“=1”?它应该只有“1”。@CodeDemon wups忘了更新我的答案,现在它应该适合你了