来自同一页面的两个PHP cookie

时间:2015-02-17 07:57:57

标签: php cookies

是否可以在同一页面上将PHP存储两个cookie 我的代码到目前为止

<?php
$cookie_name = "user";
$cookie_value = $_POST[name1];
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
?>
<?php
$cookie_name = "recipient";
$cookie_value = $_POST[recipient1];
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
?>

我希望这能设置两个cookie,一个用户和一个收件人。我该怎么做?如何修改接收代码以便接收两个 接收代码

<html>
<body>

<?php
if(!isset($_COOKIE[$cookie_name])) {
    echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
    echo "Cookie '" . $cookie_name . "' is set!<br>";
    echo "Value is: " . $_COOKIE[$cookie_name];
}
?>

</body>
</html>

0 个答案:

没有答案