PHP code example of qanna / session-bag

1. Go to this page and download the library: Download qanna/session-bag library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qanna / session-bag example snippets


   $session = new Session();

   $session->start();

   $session->has("errors");

   $session->push("email", "[email protected]");

   $default = null;
   $session->get("errors", $default);

   $session->flash('status', 'Your profile has been updated.');

   $session->getFlash('status');

   // Prevent all the flash data from being removed
   $session->reflash();

   // Prevent specific flash message(s) from being removed
   $session->reflash(['email', 'username']);

   $data = [
    'username' => 'example',
    'email' => '[email protected]',
  ];
  
  // Flash the data into the session
  $session->flash('username', $data['username']);
  $session->flash('email', $data['email']);
  
  // Reflash only the 'email' key, keeping it for the next request
  $session->reflash(['email']);
  
  // Now, let's retrieve the flashed data:
  echo $session->getFlash('username'); // Outputs: example
  echo $session->getFlash('email');    // Outputs: [email protected]
  
  // At this point, only 'email' remains in the flash data, 
  // 'username' is no longer available for future requests.