- <?php
- /**
- * Created by PhpStorm.
- * User: admin.Li
- * Date: 2018/5/16
- * Time: 10:40
- */
- namespace app\index\controller;
- use think\Cookie;
- use think\Controller;
- 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
来源: http://www.bubuko.com/infodetail-2603125.html