Cookie的使用

<?php
/**
 * Created by PhpStorm.
 * User: admin.Li
 * Date: 2018/5/16
 * Time: 10:40
 */

namespace appindexcontroller;

use thinkCookie;
use thinkController;

class Cookies extends Controller
{
    //设置cookie
    public function setCookie(){
        // 设置Cookie 有效期为 3600秒
        Cookie::set('name','李四',3600);
        // 设置cookie 前缀为think_
        //Cookie::set('name','value',['prefix'=>'think_','expire'=>3600]);
        // 支持数组
        //Cookie::set('name',[1,2,3]);
        dump(Cookie::has('name'));
    }

    public function getCookie(){
        dump(Cookie::get('name'));
        // 获取指定前缀的cookie值
        //Cookie::get('name','think_');
    }

    public function delCookie(){
        // 清空指定前缀的cookie
        Cookie::clear('tp_');
    }
}
Cookies.php
原文地址:https://www.cnblogs.com/lichao666888/p/9044985.html