项目作者: delfimov

项目描述 :
PSR-11 compatible easy to use library for managing PHP built-in sessions
高级语言: PHP
项目地址: git://github.com/delfimov/Session.git
创建时间: 2018-02-15T12:35:27Z
项目社区:https://github.com/delfimov/Session

开源协议:MIT License

下载


License

Session

PSR-11 compatible easy to use library for managing PHP built-in sessions. PDO handler included.

Requirements

How to install

Add this line to your composer.json file:

  1. "delfimov/session": "~1.0"

or

  1. composer require delfimov/session

How to configure

The session management system supports a number of configuration options
which you can place in your php.ini file or redefine in your code.

The most important settings with recommended values:

  1. session.name = PHPSESSID
  2. session.gc_probability = 1
  3. session.gc_divisor = 1000
  4. session.gc_maxlifetime = 2592000
  5. ; lifetime of sessions = 60*60*24*30 = 30 days
  6. session.use_cookies = 1
  7. session.use_only_cookies = 1
  8. session.cookie_lifetime = 2592000
  9. ; same as session lifetime

I highly recommend to use https protocol and marks the cookie as accessible
only through the HTTP protocol.

  1. session.cookie_secure = 1
  2. session.cookie_httponly = 1

See PHP Sessions Runtime Configuration
for more details.

An example

See example directory for sources.

  1. require_once __DIR__ . '/../vendor/autoload.php';
  2. $session = new DElfimov\Session\Session(
  3. new DElfimov\Session\Handlers\PDOHandler(
  4. new \PDO('mysql:dbname=testdb;host=127.0.0.1', 'dbuser', 'dbpass')
  5. )
  6. );
  7. $session->set('a', 'value a');
  8. try {
  9. echo $session->get('a');
  10. } catch (\Exception $e) {
  11. echo 'Caught exception: ', $e->getMessage(), "\n";
  12. }
  13. if ($session->has('b')) {
  14. echo 'Wonder!';
  15. }
  16. $session->remove('a');

TODO

  • Better code coverage
  • Handlers