8000 GitHub - gemingcao/cookie-helper: This is a general-purpose class that allows to manage PHP built-in cookies and the cookies variables passed via $_COOKIE superglobal
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

This is a general-purpose class that allows to manage PHP built-in cookies and the cookies variables passed via $_COOKIE superglobal

Notifications You must be signed in to change notification settings

gemingcao/cookie-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cookie-helper

一个操作$_COOKIE的类。

安装

在你的composer.jsonrequire项添加:

"gemingcao/cookie-helper": "~1.0"

或者composer直接安装:

composer require gemingcao/cookie-helper:~1.0

Cookie helper

你可以全局实例化CookieHelper类:

  $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();

License

MIT

About

This is a general-purpose class that allows to manage PHP built-in cookies and the cookies variables passed via $_COOKIE superglobal

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

0