2017 © Pedro Peláez
 

library cookie

Your friendly, furry cookie monster. Get and set cookies with ease.

image

codezero/cookie

Your friendly, furry cookie monster. Get and set cookies with ease.

  • Monday, August 17, 2015
  • by codezero
  • Repository
  • 2 Watchers
  • 5 Stars
  • 8,507 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

PHP Cookies

GitHub release License Build Status Code Coverage Scrutinizer Code Quality Total Downloads, (*1)

ko-fi, (*2)

Get and set cookies in vanilla PHP with ease. A Laravel implementation is included, but this has no real advantages if you only use Laravel., (*3)

CAUTION! Never store sensitive data in a cookie!, (*4)

Installation

Install this package through Composer:, (*5)

composer require codezero/cookie

Vanilla PHP Implementation

Autoload the vendor classes:, (*6)

require_once 'vendor/autoload.php'; // Path may vary

And then use the VanillaCookie implementation:, (*7)

$cookie = new \CodeZero\Cookie\VanillaCookie();

If you want your cookies to be encrypted, pass an instance of codezero/encrypter to the Cookie class. You will also need to provide it with an encryption key that is needed to decrypt the cookie later on., (*8)

$key = 'my secret app key';
$encrypter = new \CodeZero\Encrypter\DefaultEncrypter($key);
$cookie = new \CodeZero\Cookie\VanillaCookie($encrypter);

TIP: Laravel automagically encrypts cookies by default!, (*9)

Laravel 5 Implementation

You can "make" (or inject) a Cookie instance anywhere in your app:, (*10)

$cookie = \App::make('CodeZero\Cookie\Cookie');

TIP: Laravel's IoC container will automatically provide the Laravel specific Cookie implementation. This will use Laravel's Cookie goodness behind the scenes!, (*11)

Usage

This will return null if the cookie doesn't exist or is expired., (*12)

$cookieValue = $cookie->get('cookieName');

If you don't specify $minutesValid, a default of 60 minutes will be used., (*13)

$minutesValid = 120;
$cookie->store('cookieName', 'cookieValue', $minutesValid);

5 years feels like forever... ;), (*14)

$cookie->forever('cookieName', 'cookieValue');

If the cookie doesn't exist, nothing will happen..., (*15)

$cookie->delete('cookieName');

You can check if a cookie exists. However, keep in mind that a cookie will not be available immediately. It will be on the next page load., (*16)

if ($cookie->exists('cookieName')) {
    // The cookie exists!
}

Testing

$ composer run test

Security

If you discover any security related issues, please e-mail me instead of using the issue tracker., (*17)

License

The MIT License (MIT). Please see License File for more information., (*18)

The Versions

17/08 2015

dev-master

9999999-dev

Your friendly, furry cookie monster. Get and set cookies with ease.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ivan Vermeyen

laravel php cookie encrypt

17/08 2015

1.0.2

1.0.2.0

Your friendly, furry cookie monster. Get and set cookies with ease.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ivan Vermeyen

laravel php cookie encrypt

30/03 2015

1.0.1

1.0.1.0

Your friendly, furry cookie monster. Get and set cookies with ease.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ivan Vermeyen

laravel php cookie encrypt

28/03 2015

1.0.0

1.0.0.0

Your friendly, furry cookie monster. Get and set cookies with ease.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ivan Vermeyen

laravel php cookie encrypt