Download the PHP package mmdm/sim-session without Composer
On this page you can find all versions of the php package mmdm/sim-session. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mmdm/sim-session
More information about mmdm/sim-session
Files in mmdm/sim-session
Package sim-session
Short Description A simple yet nice session management library
License MIT
Informations about the package sim-session
Simplicity Session
A library for session management.
Features
- Simple sessions
- Time sessions
- Flash sessions
- Encrypted and secure
- Easy to use
Install
composer
Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.
Just add line below to autoload files:
and you are good to go.
How to use
Note: When you instantiate new session object, it will start session if it did not started yet.
Use with Crypt library
If you need more security on sessions, use Crypt library.
If you don't need some of your sessions to be secure, pass false as last parameter of set methods.
Available functions
- start(bool $regenerate = false, bool $delete_old_session = false)
This method starts session. To regenerate it, pass true as first argument.
NOTE: It checks if session is started yet, if not then start it.
NOTE: By default it'll not delete previous session but you can make this happen by send boolean as second parameter.
- close()
This method close a started session.
- hasStart(): bool
This method check if PHP session has started.
- set(string $key, $value, bool $encrypt = true): ISession
This method set $key to session with $value. To prevent encrypting when Crypt is specified through construct method, pass false as last parameter to not encrypt $value.
Note: To store multidimensional array in session, $key can be dotted separated strings.
exp. foo.bar => $_SESSION['foo']['bar'].
- get(string $key = null, $prefer = null): mixed
This method get value of $key from session. If there is no session with key of $key it will return $prefer instead that can be specified through second argument - default is NULL.
Note: To get multidimensional array from session, $key can be dotted separated strings.
exp. foo.bar => $_SESSION['foo']['bar'].
- remove(string $key): ISession
This method removes value of $key from session.
Note: To remove multidimensional array from session, $key can be dotted separated strings.
exp. foo.bar => $_SESSION['foo']['bar'].
- has(string $key): bool
This method checks if $key is exists in sessions.
Note: To check multidimensional array in session, $key can be dotted separated strings.
exp. foo.bar => $_SESSION['foo']['bar'].
- setTimed(string $key, $value, $time = 300, bool $encrypt = true): ISession
This method is like simple set method, the only difference is $time. With this feature you can define timer for a session value. Default value is 300 seconds.
- getTimed(string $key = null, $prefer = null): mixed
This method is like simple get method.
- removeTimed(?string $key): ISession
This method is like simple remove method. The only difference is you can pass NULL to remove all timer sessions
- hasTimed(string $key): bool
This method is like simple has method.
- setFlash(string $key, $value, bool $encrypt = true): ISession
This method is like simple set method.
- getFlash(string $key = null, $prefer = null, $delete = true): mixed
This method is like simple get method. The only difference is after get a flash session, default behavior is to remove that session, but you can make it not to remove through last parameter.
- removeFlash(?string $key = null): ISession
This method is like simple remove method. The only difference is you can pass NULL to remove all timer sessions
- hasFlash(string $key): bool
This method is like simple has method.
Dependencies
There is just one dependency and it is Crypt library. With this feature, if any session hijacking happens, they can't see actual data because it is encrypted.
License
Under MIT license.