nakome
10/30/2017 - 4:29 AM

php class utils

php class utils

<?php

class Crypt{
    /**
     * Encrypted
     */
    public function set($str = '',$key = '@~#~€') {
        $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $result = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, utf8_encode($str), MCRYPT_MODE_ECB, $iv);
        return base64_encode($result);
    }

    /**
     * Decrypted
     */
    public function get($str= '',$key = '@~#~€') {
        $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $result = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, base64_decode($str), MCRYPT_MODE_ECB, $iv);
        return $result;
    }
}



class Request{
    public function get($name = ''){
        if(array_key_exists($name, $_GET)){
            $request = ($_GET[$name]) ? $_GET[$name] : false;
            return $request;
        }
    }
    public function post($name = ''){
        if(array_key_exists($name, $_POST)){
            $request = ($_POST[$name]) ? $_POST[$name] : false;
            return $request;
        }
    }
}

class Image extends Barrio
{
    public function uri($image = '',$type = 'jpg'){
        // Read image path, convert to base64 encoding
        $imageData = base64_encode(file_get_contents($image));
        // Format the image SRC:  data:{mime};base64,{data};
        $src = 'data:image/image/'.$type.';base64,'.$imageData;
        // Echo out a sample image
        return '<img class="mb-5" src="'.$src.'">';
    }
}