基于PHP创建Cookie数组的详解
程序员文章站
2023-11-10 15:17:46
创建:复制代码 代码如下:setcookie("icnet[reg]", "this is reg cookie", time() + 3600);setcookie("i...
创建:
setcookie("icnet[reg]", "this is reg cookie", time() + 3600);
setcookie("icnet[active]", "this is login cookie.", time() + 3600);
print_r($_cookie);
/*result:
array ( [icnet] => array ( [reg] => this is reg cookie [active] => this is login cookie ) [phpsessid] => nsi2q5upuvqrik6notaohjd7p3 )
*/
读取:
echo $_cookie['icnet']['reg'];
echo $_cookie['icnet']['active'];
//或者
$arr_cookie = $_cookie['icnet'];
echo $arr_cookie['reg'];
echo $arr_cookie['active'];
销毁:
setcookie('icnet[reg]', '', time() - 3600);
setcookie('icnet[active]', '', time() - 3600);
复制代码 代码如下:
setcookie("icnet[reg]", "this is reg cookie", time() + 3600);
setcookie("icnet[active]", "this is login cookie.", time() + 3600);
print_r($_cookie);
/*result:
array ( [icnet] => array ( [reg] => this is reg cookie [active] => this is login cookie ) [phpsessid] => nsi2q5upuvqrik6notaohjd7p3 )
*/
读取:
复制代码 代码如下:
echo $_cookie['icnet']['reg'];
echo $_cookie['icnet']['active'];
//或者
$arr_cookie = $_cookie['icnet'];
echo $arr_cookie['reg'];
echo $arr_cookie['active'];
销毁:
复制代码 代码如下:
setcookie('icnet[reg]', '', time() - 3600);
setcookie('icnet[active]', '', time() - 3600);