GithubHelp home page GithubHelp logo

delfimov / session Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 30 KB

PSR-11 compatible easy to use library for managing PHP built-in sessions

License: MIT License

PHP 100.00%
php sessions handler psr-11 pdo

session's Introduction

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:

"delfimov/session": "~1.0"

or

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:

session.name = PHPSESSID
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 2592000
; lifetime of sessions = 60*60*24*30 = 30 days
session.use_cookies = 1
session.use_only_cookies = 1
session.cookie_lifetime = 2592000
; same as session lifetime

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

session.cookie_secure = 1
session.cookie_httponly = 1

See PHP Sessions Runtime Configuration for more details.

An example

See example directory for sources.

require_once __DIR__ . '/../vendor/autoload.php';
$session = new DElfimov\Session\Session(
    new DElfimov\Session\Handlers\PDOHandler(
            new \PDO('mysql:dbname=testdb;host=127.0.0.1', 'dbuser', 'dbpass')
    )
);

$session->set('a', 'value a');

try {
    echo $session->get('a');
} catch (\Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

if ($session->has('b')) {
    echo 'Wonder!';
}

$session->remove('a');

TODO

  • Better code coverage
  • Handlers

session's People

Contributors

delfimov avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.