Forked from mkdizajn/php encode_decode helper function.php
Created
February 10, 2016 11:25
-
-
Save inlife/293822f9d6c03055bad0 to your computer and use it in GitHub Desktop.
php encode/decode helper function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/html; charset=utf-8'); | |
/** | |
* [helper fn for en/de (crypt) strings] | |
* @var string | |
*/ | |
$mod = ( isset( $_GET['mod'] ) ? $_GET['mod'] : '' ); | |
$val = ( isset( $_GET['val'] ) ? $_GET['val'] : '' ); | |
$key = 'your password for encryption'; | |
function hideinfo( $key, $string ){ return rawurlencode( base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))))); } | |
function showinfo( $key, $string ){ return rawurldecode( rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode(rawurldecode($string)), MCRYPT_MODE_CBC, md5(md5($key))), "\0")); } | |
if ( $mod == 'get' && $val <> '' ){ // decode key and return it back! | |
global $key; | |
echo showinfo( $key, $val ) ; | |
exit(); | |
} elseif ( $mod == 'set' && $val <> '' ){ // encode key and return back val encripted! | |
global $key; | |
echo hideinfo( $key, $val ) ; | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment