Skip to content

popphp/pop-cookie

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

pop-cookie

Build Status Coverage Status

Join the chat at https://popphp.slack.com Join the chat at https://discord.gg/TZjgT74U7E

Overview

pop-cookie is a component used to securely create and manage cookies in a PHP web environment. With it, you can set and retrieve cookie values, as well as set required configuration options for the web application environment.

pop-cookie is a component of the Pop PHP Framework.

Top

Install

Install pop-cookie using Composer.

composer require popphp/pop-cookie

Or, require it in your composer.json file

"require": {
    "popphp/pop-cookie" : "^4.0.0"
}

Top

Quickstart

The cookie object can be created using the getInstance() method, which takes an options array:

use Pop\Cookie\Cookie;

$cookie = Cookie::getInstance([
    'path'   => '/',
    'expire' => time() + 3600,
]);

Available options

$options = [
    'path'     => '/',
    'expire'   => time() + 3600,
    'domain'   => 'www.domain.com',
    'secure'   => true,
    'httponly' => true,
    'samesite' => 'Lax'  // 'Lax', 'Strict', 'None'
];

From there, you can interact with the cookie object.

Setting cookie values

// Set cookie values
$cookie->foo = 'bar';
$cookie['baz'] = 123;

Accessing cookie values

echo $cookie->foo;
echo $cookie['baz'];

Unset cookie values

unset($cookie->foo);
unset($cookie['baz']);

Top