| 1 |
[![Latest Stable Version]](https://packagist.org/packages/wikimedia/php-session-serializer) [![License]](https://packagist.org/packages/wikimedia/php-session-serializer) |
| 2 |
|
| 3 |
php-session-serializer |
| 4 |
====================== |
| 5 |
|
| 6 |
php-session-serializer is a PHP library that provides methods that work like |
| 7 |
PHP's [session_encode][phpencode] and [session_decode][phpdecode] |
| 8 |
functions, but don't mess with the `$_SESSION` superglobal. |
| 9 |
|
| 10 |
It supports the `php`, `php_binary`, and `php_serialize` serialize handlers. |
| 11 |
`wddx` is not supported, since it is inferior to `php` and `php_binary`. |
| 12 |
|
| 13 |
|
| 14 |
Usage |
| 15 |
----- |
| 16 |
|
| 17 |
```php |
| 18 |
use Wikimedia\PhpSessionSerializer; |
| 19 |
|
| 20 |
// (optional) Send logs to a PSR-3 logger |
| 21 |
PhpSessionSerializer::setLogger( $logger ) |
| 22 |
|
| 23 |
// (optional) Ensure that session.serialize_handler is set to a usable value |
| 24 |
PhpSessionSerializer::setSerializeHandler(); |
| 25 |
|
| 26 |
// Encode session data |
| 27 |
$string = PhpSessionSerializer::encode( $array ); |
| 28 |
|
| 29 |
// Decode session data |
| 30 |
$array = PhpSessionSerializer::decode( $string ); |
| 31 |
``` |
| 32 |
|
| 33 |
Running tests |
| 34 |
------------- |
| 35 |
|
| 36 |
composer install --prefer-dist |
| 37 |
composer test |
| 38 |
|
| 39 |
|
| 40 |
History |
| 41 |
------- |
| 42 |
|
| 43 |
This library was created to support custom session handler [read][] and |
| 44 |
[write][] methods that are more useful than blindly storing the serialized data |
| 45 |
that PHP gives to custom handlers. |
| 46 |
|
| 47 |
|
| 48 |
--- |
| 49 |
[phpencode]: https://php.net/manual/en/function.session-encode.php |
| 50 |
[phpdecode]: https://php.net/manual/en/function.session-decode.php |
| 51 |
[read]: https://php.net/manual/en/sessionhandlerinterface.read.php |
| 52 |
[write]: https://php.net/manual/en/sessionhandlerinterface.write.php |
| 53 |
[Latest Stable Version]: https://poser.pugx.org/wikimedia/php-session-serializer/v/stable.svg |
| 54 |
[License]: https://poser.pugx.org/wikimedia/php-session-serializer/license.svg |