PHP code example of ichynul / tp-cookie

1. Go to this page and download the library: Download ichynul/tp-cookie library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ichynul / tp-cookie example snippets


use tpcookie\Cookie;

Cookie::set('name', 'value', 3600);//设置cookie,3600秒后过期
Cookie::get('name');//获取cookie
Cookie::delete('name');//删除cookie
Cookie::has('name');//判断cookie是否存在

$option = ['expire'=>3600, 'path'=>'/', 'domain'=>'', 'secure'=>false, 'httponly'=>false, 'samesite'=>''];
Cookie::set('name', 'value', $option);//option为数组


//`cookie()` 或 `tp_cookie()`

function tp_cookie(string $name, $value = '', $option = null){
    //
}


tp_cookie('name', 'value', 3600);//设置cookie,3600秒后过期
tp_cookie('name');//获取cookie
tp_cookie('name', null);//删除cookie
tp_cookie('?name');//判断cookie是否存在

tp_cookie('name', 'value', $option);//option为数组