如何设置具有多个值的php cookie? [英] How do you set a php cookie with multiple values?

查看:119
本文介绍了如何设置具有多个值的php cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个存储用户名和用户ID的PHP cookie。或者最好只是使用一个来获得另一个?

I want to create a php cookie that stores the username and the userid. Or is it better to just use one to get the other?

推荐答案

    <?php
// set the cookies
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");

// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
    foreach ($_COOKIE['cookie'] as $name => $value) {
        $name = htmlspecialchars($name);
        $value = htmlspecialchars($value);
        echo "$name : $value <br />\n";
    }
}
?>

http://php.net/manual/en/function.setcookie.php

这篇关于如何设置具有多个值的php cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆