Nishchay Sessions like read limit till next request count and more


A session can be defined as a server-side storage of information that is desired to persist throughout the user's interaction with the web site or web application.

HTTP is stateless, means every request is unique to server. To identity request to server client and server shares cookie between them. In PHP this cookie is known as PHPSESSID which stores unique identification string. On first request, when we create session PHP creates unique session id and sends back in header as cookie.

On each subsequent requests browser sends this cookie id to server. This way server identifies each request.

Session Management

Session data

Session data are stored on server side for session id. For each request server looks for cookie in request header then it takes value of cookie which is session id. Then server fetches data associated with session id. We can store any kind of information in session data. But this should be limited to temporary data. Permanent should be stored in database.

Session Data

What should be stored in session

Session should contain data like userId , user role, user group etc. Session data should only contain ids or name of things.

Nishchay Session

Nishchay has its own implementation for session, how it processes and manges session is different than core php and any other PHP framework.

Unlike core PHP and any other PHP framework, nishchay has various type sessions. Below are various sessions which available in nishchay framework.

  1. Read limit
  2. Till next request
  3. Scope
  4. Context
  5. Normal
  6. Cookie
  7. Conditional

To learn more session read it at nishchay learning center session page.

Read limit

Read limit sessions gets auto removed when its read limit is reached. Suppose we created one read limit with its read limit set to 3, this sessions gets removed when it has been read 3 times.

See below example how we can create read limit session:

$session = new NIshchay\Session\ReadLimit(3);

$session->token = 'TOKEN';

If we want to create read limit with different than create another instance with new limit:

$coupanSession = new NIshchay\Session\ReadLimit(1);

$coupanSession->code = 'ABSBS';

We can create any number of instance of sessions and this remains same for all type of sessions.

Till next request count

This type of session expires after given number of request. This is required when we want to have session data which should exists till next number requests.

$session = Nishchay\Session\TillNextRequestCount(5);

$session->validity = 'ASASDA';
Flash session

Flash sessions are expire after next request. To create flash use TillNextRequestCount session with value 1. See below code:

$session = Nishchay\Session\TillNextRequestCount(1);
More session type

Read session in learning center.