Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

PHP session storage for Symfony's HTTP layer

License

NotificationsYou must be signed in to change notification settings

bolt/session

Repository files navigation

PHP session handler built on Symfony components and supporting Silex v1 & v2.

Supports session storage with:

  • Doctrine cache
  • Symfony Filesystem
  • Bolt Filesystem
  • Memcache
  • Memcached
  • PSR-6 Cache
  • PSR-16 Simple Cache
  • Redis

Service Providers

Silex 1

useBolt\Session\Bridge\Silex1\SessionServiceProvider;useSilex\Application;$app =newApplicaiton();$app->register(newSessionServiceProvider());

Silex 2

useBolt\Session\Bridge\Silex2\SessionServiceProvider;useSilex\Application;$app =newApplicaiton();$app->register(newSessionServiceProvider());

Browser cookies

By default, Bolt will inherit the settingscookies_lifetime,cookies_domain,andenforce_ssl (forcookie_secure) should no override options be set, asper the order of precedence explained in the introduction.

However, there are several override settings available, should you need morefine-grained control.

Life time

Time in seconds, that a cookie will be valid for. Setting this value to 0 means"until the browser is closed".

KeyDefault
cookie_lifetime1209600Integer >= 0

In.php.ini this setting issession.cookie_lifetime.

Base URI path

Specifies URI path to set in the session cookie.

KeyDefault
cookie_path/URI string

In.php.ini this setting issession.cookie_path.

Override domain name

Specifies the domain to set in the session cookie. Default is null, meaning thehost name of the server which generated the cookie.

KeyDefault
cookie_domainHTTP(S) request host nameA fully qualified domain name

In.php.ini this setting issession.cookie_domain.

Enforce HTTPS requests

Setting this totrue will enforce a HTTPS connection requirement to set, anduse, the session cookie.

KeyDefault
cookie_securefalseBoolean on/off toggle

In.php.ini this setting issession.cookie_secure.

Restricting request to the HTTP protocol

Marks the cookie as accessible only through the HTTPprotocol, blockingaccess to requests by things such as JavaScript.

This setting can effectively help to reduce identity theft through XSS attacks,although browser support may vary.

KeyDefault
cookie_httponlytrueBoolean on/off toggle

Setting in yourconfig.yml:

In.php.ini this setting issession.cookie_httponly.

Session ID generation

Session IDs are randomly generated to uniquely identify a user's session. Boltinternally handles this generation in a fashion close to how PHP 7.1+ now doesto better ensure the uniqueness of the generated ID.

By default, both PHP & Bolt use an ID length of 32, which should provide onlya small chance of collisions, or predictability, of the generated ID.

On hosts with a consistent amount of available CPU resources, and a focus onsecurity, you should consider a number of 48 or greater. However, this willincrease the server load, and amount of time taken to generate session IDs.

An example of generating 1,000 session IDs on PHP 7.0 and an Intel i5-5200:

ID lengthmilliseconds
320.002059
480.002560
640.003031
1280.003016
2560.004132

Maximum value supported is 256.

KeyDefault
sid_length32Integer between 32 & 256

In PHP 7.1+ the.php.ini this setting issession.sid_length.

Session storage handler

Session storage handling, by default, is our filesystem layer. However, we alsosupport Redis & Memcached for more advanced use-cases.

KeyDefault
save_handlerfilesystemfilesystem,redis,memcached

Setting in yourconfig.yml:

In.php.ini this setting issession.save_handler.

Note: Some web hosting providers may implement alternative session handlingthat is not compatible with Bolt Session.

Should you encounter exceptions fromSessionServiceProvider indicatingproblems with PHP's system save path, setsave_handler: filesystem,and thesave_path option shown below.

Using the Redis handler

When using Redis as the handler, the following options are also under theconnections subkey, of the session options:

KeyDefault
hostlocalhostHost name or I.P. address of Redis server
port6379TCP port of Redis server
timeout0.0A float value in seconds (0.0 meanings unlimited)
persistentnullBoolean to toggle persistent connections
passwordnull(optional) Authenticate the connection using a password.Warning: The password is sent in plain-text over the network.
prefixnull(optional) Prefix string used on all keys
databasenullInteger of the database index to connect to

If the native\Redis library is available, it will be used as the handler forRedis, if not available, it will instead check for the PHP implementation ofthe native library,\Predis\Client and use that.

Using the Memcached handler

When using Memcached as the handler, the following options are also under theconnections subkey, of the session options:

KeyDefault
hostlocalhostString host name or I.P. address of Memcached server
port11211TCP port of Memcached server
weight0(optional) The weight of the server relative to the total weight of all the servers in the pool. This controls the probability of the server being selected for operations.
expiretime86400(optional) Life time in seconds of stored keys
prefixsf2s(optional) Prefix string used on all keys

Saved session file path

Session data is cached in between requests, andis not cleared by thenormal cache clearing functionality.

Instead, it uses garbage collection to manage deletion of expired sessions. Seethe section below on garbage collection for details on configuration.

KeyDefault
save_pathcache://.sessionsPath passed to thesave_handler

Note: Manually deleting session data on a live server isnever advised.Should this ever be required on a live server, ensure all users are logged off,and place the site into maintenance mode first.

In.php.ini this setting issession.save_path.

Using the Filesystem handler

When using the default filesystem handler, thesave_path parameter needs tobe in the form of{mount point}://{path}.

See theOverview of Bolt's Filesystem page for details onthe mount points available in Bolt.

Warning: If you set this to a world-readable directory, such as/tmp,other users on the server may be able to hijack sessions, or extractpotentially sensitive data.

Using the Redis handler

When using Redis as the handler,save_path should be defined in the formattcp://IPADDRESS:PORT, with a default oftcp://127.0.0.1:6379.

Using the Memcached handler

When using Memcached as the handler,save_path should be defined in theformatIPADDRESS:PORT, with a default of127.0.0.1:11211.

Garbage collection

Session garbage collection is the removal of sessions older than the configuredmaximum life time.

The need to perform garbage collection is determined based on a random probabilitycalculation during the initialisation of each session.

Maximum life time

The maximum life time setting specifies the number of seconds after whichsession data will be seen as 'garbage' and potentially cleaned up.

KeyDefault
gc_maxlifetime1209600Integer of seconds

In.php.ini this setting issession.gc_maxlifetime.

Probability & divisor

The settinggc_divisor coupled withgc_probability define the probability thatthe garbage collection (GC) process is performed.

In Bolt's session storage handler, the probability is calculated by generatinga random number between 0 andgc_divisor. If the value ofgc_probability isgreater than the random number, garbage collection will be performed, andsession files older than the maximum configured life time are removed.

Note: To disable garbage collection, setgc_probability to-1.

KeyDefault
gc_probability1Integer
gc_divisor1000Integer

In.php.ini these settings are:



[8]ページ先頭

©2009-2025 Movatter.jp