PHPackages                             alejoluc/lazysession - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alejoluc/lazysession

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alejoluc/lazysession
====================

Package to use sessions without having to call session\_start(). It will not call session\_start() unless the request uses sessions.

0.1.4(7y ago)034MITPHPPHP &gt;=5.4.0

Since Jan 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/alejoluc/LazySession)[ Packagist](https://packagist.org/packages/alejoluc/lazysession)[ Docs](https://github.com/alejoluc/LazySession)[ RSS](/packages/alejoluc-lazysession/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (5)Used By (0)

LazySession
===========

[](#lazysession)

This package allows you to use sessions without having to worry about whether you have properly called `session_start()` or not.

Instead of using `session_start()` on every request, regardless or whether said request will actually need sessions or not, this class will automatically start the session when you try to access it's data in any way. By avoiding `session_start()` when a request does not need it you improve the usage of your server's resources, especially since the default method for storing sessions is using the filesystem, which can be relatively slow.

The interface is very similar to the one used natively by PHP, and allows you to get, create, modify or delete session data via methods, or by using session keys either as array keys or object properties. See example below for clarification.

Although the class provides methods for using common session functions, for example, to change the session storage path, it is not needed that such functions be called from the instantiated object, nor are you limited to the methods that have been implemented to access native functions: since the class uses the native PHP implementation for sessions, any `session_*` function you call in your code will work nicely with the class.

Installation
------------

[](#installation)

From the command line:

`composer require alejoluc/lazysession`

Or write manually in `composer.json`:

```
{
  "require": {
    "alejoluc/lazysession": "*"
  }
}
```

Example usage: Instantiating the class and accessing session data in a crude login example
------------------------------------------------------------------------------------------

[](#example-usage-instantiating-the-class-and-accessing-session-data-in-a-crude-login-example)

```
