sessions.php 1.55 KB
<?php
    /**
	* @Description : File session or cookie
	* @Package : Drag & Drop Multiple File Upload - Contact Form 7
	* @Author : CodeDropz
	*/

    if ( ! defined( 'ABSPATH' ) || ! defined('dnd_upload_cf7') || ! defined('dnd_upload_cf7_PRO') ) {
		exit;
	}

    class CodeDropz_Uploader_Sessions {

        private static $instance = null;

        public static function get_instance() {
            if( null === self::$instance ) {
                self::$instance = new self();
            }
            return self::$instance;
        }
        
        /**
        * Set Custom Cookie/Session - setcookie may delay
        * @ param : name(string), value(array), expire(2hours)
        */

        public function set_cookie( $name, $value, $expire = 7200 ) {
            $_SESSION[ $name ] = ( is_array( $value ) ? maybe_serialize( $value ) : $value );
        }

        /**
        * Get Cookie/Session
        * @ param : name (string)
        * @ return : array or string
        */

        public function get_cookie( $name ) {
            if( isset( $_SESSION[ $name ] ) ) {
                return ( is_serialized( $_SESSION[ $name ] ) ? maybe_unserialize( stripslashes( $_SESSION[ $name ] ) ) : $_SESSION[ $name ] );
            }
            return false;
        }

        /**
        * Delete Cookie/Session
        * @ param : name(string)
        */

        public function delete_cookie( $name ) {
            if( isset( $_SESSION[ $name ] ) ) {
                unset( $_SESSION[ $name ] );
                $_SESSION[ $name ] = '';
            }
        }

    }