码迷,mamicode.com
首页 > 其他好文 > 详细

Cookie的使用

时间:2018-05-16 12:50:02      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:有效期   splay   bsp   open   col   clear   set   pac   spl   

技术分享图片
<?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

 

Cookie的使用

标签:有效期   splay   bsp   open   col   clear   set   pac   spl   

原文地址:https://www.cnblogs.com/lichao666888/p/9044985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!