Skip to content

Instantly share code, notes, and snippets.

@mkdizajn
Last active April 17, 2017 22:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mkdizajn/88a528f2a9ecee880c2e to your computer and use it in GitHub Desktop.
Save mkdizajn/88a528f2a9ecee880c2e to your computer and use it in GitHub Desktop.
php encode/decode helper function
<?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