PHP code example of gemingcao / cookie-helper

1. Go to this page and download the library: Download gemingcao/cookie-helper 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/ */

    

gemingcao / cookie-helper example snippets


  $cookie = new \Gemingcao\Helper\CookieHelper();

  // 检测cookie是否存在
  $exists = $cookie->exists('my_key');
  $exists = isset($cookie->my_key);
  $exists = isset($cookie['my_key']);

  // 获取一个cookie
  $my_value = $cookie->get('my_key', 'default');
  $my_value = $cookie->my_key;
  $my_value = $cookie['my_key'];

  // 设置一个cookie
  $app->cookie->set('my_key', 'my_value');
  $cookie->my_key = 'my_value';
  $cookie['my_key'] = 'my_value';

  // 合并cookie数组
  $app->cookie->merge('my_key', ['first' => 'value']);
  $cookie->merge('my_key', ['second' => ['a' => 'A']]);
  $letter_a = $cookie['my_key']['second']['a'];  // "A"

  // 删除一个cookie
  $cookie->delete('my_key');
  unset($cookie->my_key);
  unset($cookie['my_key']);

  // 销毁cookie
  $cookie::destroy();