Code Monkey home page Code Monkey logo

cookiesession's Introduction

CookieSession

CookieSession is a very light library to manage easily and simply the Session and Cookie with PHP 7+ (and without spending time by configuring and securing them).

Composer Installation

You can add it easily in your projec by using Composer.

$ composer require ph-7/cookiesession

Then, include Composer's autoload

require_once 'vendor/autoload.php';

Manual Installation

If you don't use Composer, you can install it without Composer by including the following

require 'src/autoloader.php';

Usage for Session

<?php
use PH7\CookieSession\Session\Session;

$oSession = new Session;

$oSession->set('lang_pref', 'English');

// Create some sessions with an array
$aData = [
    'my_session' => 'The value',
    'another_session' => 'Another value',
    'my_name' => 'Pierre-Henry'
];
// Add these sessions
$oSession->set($aData);


// Get session
echo $oSession->get('lang_pref'); // Will display 'English'
echo $oSession->get('another_session'); // Will display 'Another value'

echo ($oSession->exists('my_name')) ? $oSession->get('my_name') : 'Well, well, we dont have a name in the session'; // Will display 'Pierre-Henry'

$oSession->remove('my_name'); // Remove 'my_name' session

echo $oSession->get('my_name'); // Will display nothing (empty string) as 'my_name' session has been removed

Usage with Cookie (very similar)

<?php
use PH7\CookieSession\Cookie\Cookie;

$oCookie = new Cookie;

$oCookie->set('mycookie', 'Amazing Value!');

// Create some cookies in array
$aCookies = [
    'name' => 'Pierre-Henry',
    'city' => 'Manchester',
    'job' => 'Software Engineer'
];
$oCookie->set($aCookies);

if ($oCookie->exists($aCookies)) {
    echo 'All the following cookies exist: ' . implode(', ', $aCookies);
}

echo $oCookie->get('name'); // Will display 'Pierre-Henry'
echo $oCookie->get('mycookie'); // Will display 'Amazing Value!'

$oCookie->remove($aCookies); // Remove all cookies

echo $oCookie->get('name');  // Will display nothing (empty string)

Requirements

  • PHP 7 or higher

The Author

I'm Pierre-Henry Soria, Software Developer passionate about a lot of things and currently living in Manchester city, UK

Contact

You can send an email at pierrehenrysoria [AT] gmail {D0T} COM or at phy {AT} hizup [D0T] UK

License

Under General Public License 3 or later.

cookiesession's People

Contributors

jatubio avatar ph-7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

tophitter jatubio

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.