From d181219e4001f4309da2924a4e68eeaafe89902c Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 19 Oct 2017 20:11:28 +0200 Subject: [PATCH] Add documentation about cookies and their usage to README --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 5aa115c..c5a3c5e 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ Migrating from an earlier version of this project? See our [upgrade guide](Migra * [Assigning roles to users](#assigning-roles-to-users) * [Taking roles away from users](#taking-roles-away-from-users) * [Checking roles](#checking-roles-1) + * [Cookies](#cookies) + * [Renaming the library’s cookies](#renaming-the-librarys-cookies) * [Utilities](#utilities) * [Creating a random string](#creating-a-random-string) * [Creating a UUID v4 as per RFC 4122](#creating-a-uuid-v4-as-per-rfc-4122) @@ -896,6 +898,48 @@ catch (\Delight\Auth\UnknownIdException $e) { } ``` +### Cookies + +This library uses two cookies to keep state on the client: The first, whose name you can retrieve using + +```php +\session_name(); +``` + +is the general (mandatory) session cookie. The second (optional) cookie is only used for [persistent logins](#keeping-the-user-logged-in) and its name can be retrieved as follows: + +```php +\Delight\Auth\Auth::createRememberCookieName(); +``` + +#### Renaming the library’s cookies + +You can rename the session cookie used by this library through one of the following means, in order of recommendation: + + * In the [PHP configuration](http://php.net/manual/en/configuration.file.php) (`php.ini`), find the line with the `session.name` directive and change its value to something like `session_v1`, as in: + + ``` + session.name = session_v1 + ``` + + * As early as possible in your application, and before you create the `Auth` instance, call `\ini_set` to change `session.name` to something like `session_v1`, as in: + + ```php + \ini_set('session.name', 'session_v1'); + ``` + + For this to work, `session.auto_start` must be set to `0` in the [PHP configuration](http://php.net/manual/en/configuration.file.php) (`php.ini`). + + * As early as possible in your application, and before you create the `Auth` instance, call `\session_name` with an argument like `session_v1`, as in: + + ```php + \session_name('session_v1'); + ``` + + For this to work, `session.auto_start` must be set to `0` in the [PHP configuration](http://php.net/manual/en/configuration.file.php) (`php.ini`). + +The name of the cookie for [persistent logins](#keeping-the-user-logged-in) will change as well – automatically – following your change of the session cookie’s name. + ### Utilities #### Creating a random string