GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - stackphp/session: Session stack middleware.

This repository was archived by the owner on Jul 29, 2024. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

18 Commits
18 Commits

Folders and files

NameName
Last commit message
Last commit date
src/Stack
src/Stack
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
composer.lock
composer.lock
 
 
example.php
example.php
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

Stack/Session

Session stack middleware.

Enables the request session for subsequent middlewares.

Example

Here's an example giving a silex app access to the session using stack/stack:

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;

$app = new Silex\Application();

$app->get('/login', function (Request $request) {
    $session = $request->getSession();

    $username = $request->server->get('PHP_AUTH_USER');
    $password = $request->server->get('PHP_AUTH_PW');

    if ('igor' === $username && 'password' === $password) {
        $session->set('user', array('username' => $username));
        return new RedirectResponse('/account');
    }

    return new Response('Please sign in.', 401, [
        'WWW-Authenticate' => sprintf('Basic realm="%s"', 'site_login'),
    ]);
});

$app->get('/account', function (Request $request) {
    $session = $request->getSession();

    if (null === $user = $session->get('user')) {
        return new RedirectResponse('/login');
    }

    return sprintf('Welcome %s!', $user['username']);
});

$stack = (new Stack\Builder())
    ->push('Stack\Session');

$app = $stack->resolve($app);

Options

The following options can be used to configure stack/session:

  • session.storage.save_path (optional): The path for the NativeFileSessionHandler, defaults to the value of sys_get_temp_dir().

  • session.storage.options (optional): An array of options that is passed to the constructor of the session.storage service.

    In case of the default NativeSessionStorage, the possible options are listed on the PHP manual's session configuration page.

  • session.default_locale (optional): The default locale, defaults to en.

  • session.cookie_params (optional): Override parameter values for the session cookie as listed on the PHP manual's session_get_cookie_params page. (allowed keys: lifetime, path, domain, secure, and httponly)

Usage

The session middleware enables the Session object on the request. You can access it through the Request object:

$session = $request->getSession();

$session->start();
$foo = $session->get('foo');
$session->set('foo', 'bar');

Silex SessionServiceProvider

Note that this middleware is a replacement for the silex SessionServiceProvider. If you want to use it with silex, you might want to define the session service as follows:

$app['session'] = $app->share(function ($app) {
    return $app['request']->getSession();
});

This is only needed if you have services that depend on the session service.

Inspiration

This middleware is based on the silex SessionServiceProvider.

About

Session stack middleware.

Resources

Readme
MIT license
Activity
Custom properties

Stars

26 stars

Watchers

3 watching

Forks

6 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.