Giter Club home page Giter Club logo

session-scary's Introduction

Scary - A simple session organizer for php

Build Status License Usage codecov Codacy Badge

A very simple session organizer that may help you for handling scary styles on php

Requirements

  • Composer for installation

Quick Start

Installation

composer require "moviet/session-scary"

Release

The current released is only support for handling happy global procedural session

Features

  • Create Single Session
  • Generate Multiple Session
  • Evaluate Session
  • Make Auto Increment
  • Custom Session Expiration
  • Regenerate Session Id
  • Remove Session

Usage

Create A Single Session

  • You can follow the humble style like below

    Scary::set('my_token')->value('11001101')->get();

    the above will equivalent

    $_SESSION['my_token'] = '11001101'
  • Then to get a single session

    Scary::read('my_token'); // output => 11001101

    Notes :

    When you refresh the browser the values will be save in session at first, you may need (eg. token, random, url)
    and don't want to lost when the page's refresh, just like common it may useful

Generate Multiple Session

  • You can fashion a session banks on easy away

    Scary::mset('My Session Manager')
       ->mkey(['Specialist','Senior','Junior'])
       ->mval(['value_1','value_2','value_3'])
       ->swap();
  • Or you may relax with a free style

    $keys = ['Specialist','Senior','Junior'];
    $values = ['Baz','Biz','Buz'];
    
    Scary::mset('My Session Manager')
       ->mkey($keys) 
       ->mval($values)
       ->swap();
  • And then to express your tailor

    Scary::read('My Session Manager','Junior'); // output => Buz

    Notes :

    When you refresh the browser the values will be save in session at first, you may need (eg. token, random, url)
    and don't want to lost when the page's refresh, just like common it may useful

Evaluate A Session

  • For single session, you can replace with new something

    Scary::change('Angry Boss','Run'); // replace other value eg. Run
  • And for multiple sets, you can replace like this

    Scary::mchange('My Bread','My Chocolato','Eat Me');

    Now that was going through changes and you can dump with yayy...

Make Auto Increment

  • For example you may want to make eg. login attempt using a single method

    Scary::set('my_key')->value('11001101')->inc(5)->get();
  • Or using multiple series

    Scary::mset('My Desire Key')
       ->mkey(['Eat','Drink','Lick','Whatever..'])
       ->mval(['Apple','Orange','Lollipop','Hufft..'])
       ->inc(5) // <=
       ->swap();

    On above example you will get an auto-increment max. 5 times, start from 0-5

  • If you want to verify eg. session loggedin, you can write like

    if (Scary::flinc('My Desire Key') !== true)
    
    // Do something

    Notes :

    It will return false when session doesn't exists, then you can do something

Custom Session Expiration

  • You can recruit a custom flash message, expirated or any creations

    Scary::set('my_key')->value('11001101')->ttl(5)->get();
  • Using multiple happy set

    Scary::mset('My Desire Key')
       ->mkey(['Smile','Happy','Affraid'])
       ->mval(['Lost','Donate','Any Expression Here'])
       ->swap();
    
    Scary::live('My Desire Key', 5) // it can be place in somewhere pages, if return false, you can do something

    Notes :

    use ttl or live like examples on above meant the session will expired within 5 minutes

Regenerate Session Id

  • You may doubt with an existing session, you can ensure with this

    if (Scary::exist('my_session_key'))
    
    // Do something
  • To regenerate session with create new id you can draw this

    Scary::newId('my_session_key');
  • Or using this to refresh session_id

    Scary::refresh('my_session_key'); // session_regenerate_id(true)

Remove Session

  • To remove a single session with work like charm

    Scary::trash('my_session_key');
  • And remove multiple session at once

    Scary::trash('chocomelo, durian, alphanut, loggadin, url, token, and...');
  • Also you can destroy all session and make them gone

    Scary::clean('my_session_key');

Example

Create A Single Session

require '__DIR__' . '/vendor/autoload.php';

use Moviet\Session\Scary;

// Generate Cross Smile Request Poorgery
$randomToken = base64_encode(random_bytes(32));

Scary::set('Emo Cry Attack')->value($randomToken)->get();

$check = Scary::read('Emo Cry Attack');

// dump : JHs+jsakjkja87823hsalwatah989jsajh+sakCacanana83729Mama=

Create Multiple Session

require '__DIR__' . '/vendor/autoload.php';

use Moviet\Session\Scary;

// Type whatever collection
$verify = 'true';

// Register what you need
$loggadId = '2928929-988787-8877-78688868';

// Type secret code etc
$randomMult = bin2hex(random_bytes(16));

// Type like Adurl
$downloadUrl = 'github.com/moviet/session-scary';

/** 
* Compile them in single bandage
*/
Scary::mset('Something key')
      ->mkey(['verify','token_key','mis-loggadin','download-url'])
      ->mval([$verify, $randomMult, $loggadId, $downloadUrl])
      ->swap();

$getClone = Scary::read('Something key','download-url');

// dump yaaaayyy : github.com/moviet/session-scary

License

Moviet/session-scary is released under the MIT public license. See LICENSE for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.