PHP Classes

File: vendor/jackbooted/util/Cookie.php

Recommend this page to a friend!
  Classes of Brett Dutton   JackBooted PHP Framework   vendor/jackbooted/util/Cookie.php   Download  
File: vendor/jackbooted/util/Cookie.php
Role: Class source
Content type: text/plain
Description: Class source
Class: JackBooted PHP Framework
Web application framework using simplified MVC
Author: By
Last change:
Date: 8 years ago
Size: 1,584 bytes
 

Contents

Class file image Download
<?php
namespace Jackbooted\Util;

use \
Jackbooted\Config\Cfg;
use \
Jackbooted\Security\Cryptography;
/**
 * @copyright Confidential and copyright (c) 2016 Jackbooted Software. All rights reserved.
 *
 * Written by Brett Dutton of Jackbooted Software
 * brett at brettdutton dot com
 *
 * This software is written and distributed under the GNU General Public
 * License which means that its source code is freely-distributed and
 * available to the general public.
 */

class Cookie extends \Jackbooted\Util\JB {
    const
CRYPTO_KEY = 'hgfads8h4325h7676asdvbe2misaj9fdsa3r';

    private static
$crypto;
    private static
$timeout;

    public static function
init () {
       
self::$crypto = new Cryptography ( self::CRYPTO_KEY );
       
self::$timeout = 14 * 24 * 60 * 60;
    }

   
/** Function to get a Cookie
     * @param $s The name of the Cookie
     * @public
     */
   
public static function get ( $s, $def='' ) {
        if ( ! isset (
$_COOKIE[$s] ) ) return $def;

        return
self::$crypto->decrypt ( $_COOKIE[$s] );
    }

   
/** Function to set a Cookie
     * @param $s The name of the Cookie
     * @param $val The value of the Cookie
     * @public
     */
   
public static function set ( $key, $val ) {
       
setcookie ( $key, self::$crypto->encrypt ( $val ) ,
                   
time () + self::$timeout,
                   
Cfg::get ( 'cookie_path', '/' ) );
    }

   
/** Function to clear a Cookie
     * @param $s The name of the Cookie
     * @public
     */
   
public static function clear ( $key ) {
       
self::set ( $key, '' );
    }
}