因此你可以将多个值合并成一个String类型的值存入cookie中
比如姓名:zhangsan年龄:25 性别:male
你可以String value = “zhangsan,25,male”;
取出来的时候可以用 value.split(",")来得到一个String[] 数组。
ASP.NET中的cookie:创建多值Cookie方法 (1)Response.Cookies["userInfo"]["userName"] = “admin"
Response.Cookies["userInfo"]["lastVisit"] = DateTime.Now.ToString()
Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(1)
ASP.NET中的cookie:创建多值Cookie方法 (2)
HttpCookie aCookie = new HttpCookie("userInfo")
aCookie.Values["userName"] = “admin"
aCookie.Values["lastVisit"] = DateTime.Now.ToString()
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
ASP.NET中的cookie:读取多值Cookie
HttpCookie aCookie = Request.Cookies["userInfo"]
string userName=aCookie.Values[“userName”]
string lastVisit=aCookie.Values[“lastVisit”]
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/strawberrylily/archive/2009/09/16/4559655.aspx
<?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) {
echo "$name : $value <br />\n"
}
}
?>
手册上的例子
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)