2017 © Pedro Peláez
 

library session

A dead simple and basic session library

image

maer/session

A dead simple and basic session library

  • Wednesday, November 18, 2015
  • by maer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 62 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

A dead simple session library in PHP

Build Status, (*1)

Manage PHP sessions and flash sessions in a simple way., (*2)

Install

Clone this repository or use composer to download the library with the following command:, (*3)

composer require maer/session 1.*

Set up

Load the library via composers autoloader:, (*4)

include '/path/to/vendor/autoload.php';

Load the library manually:, (*5)

include '/path/to/library/src/SessionInterface.php';
include '/path/to/library/src/Session.php';

Example

When a session instance is created, it will check if the session already is started. If not, it will start it using session_start()., (*6)

Managing sessions

$session = new Maer\Session\Session();

// Set a value
$session->set('my-key', 'my-value');

// Get a value
$value = $session->get('my-key');

// Add an optional second argument
$value = $session->get('non-existint-key', 'this-will-be-returned');

// Check if a key exists
if ($session->has('my-key')) {
    // Yay... it exists!
} else {
   // Darn! It didn't exist!
}

// Forget/clear/remove a session key
$session->forget('my-key');

// Forget/clear/remove all session keys and destroy the session cookie
$session->destroy();

Flash sessions

A flash session is a "one-request-only"-session. If you set a flash session, it is only accessable in the next request and will then be removed. It's perfect for things like success/status/error messages., (*7)

// Set a flash session
$session->setFlash('error', 'This is an error message');

// On the next request
$value = $session->getFlash('error');

// Add an optional second argument
$value = $session->get('non-existint-key', 'this-will-be-returned');

Both ->get(...) and ->getFlash(...) returns NULL as default if the key isn't found., (*8)


I told you it was dead simple!, (*9)

If you have any questions, suggestions or issues, let me know!, (*10)

Happy coding!, (*11)

The Versions

18/11 2015

dev-master

9999999-dev

A dead simple and basic session library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Magnus Eriksson

18/11 2015

dev-develop

dev-develop

A dead simple and basic session library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Magnus Eriksson

18/11 2015

1.0.0

1.0.0.0

A dead simple and basic session library

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Magnus Eriksson