I use the following functions to encrypt my $_GET variables (whenever I can't easily get away with using $_POST or some other way of passing information between pages.
function decryptStringArray ($stringArray, $key = "Your secret salt thingie")
{
$s = unserialize(rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode(strtr($stringArray, '-_,', '+/=')), MCRYPT_MODE_CBC, md5(md5($key))), "\0"));
return $s;
}
function encryptStringArray ($stringArray, $key = "Your secret salt thingie")
{
$s = strtr(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), serialize($stringArray), MCRYPT_MODE_CBC, md5(md5($key)))), '+/=', '-_,');
return $s;
}
function prepareUrl($url, $key = "Your secret salt thingie")
{
$url = explode("?",$url,2);
if(sizeof($url) <= 1)
return $url;
else
return $url[0]."?params=".encryptStringArray($url[1],$key);
}
function setGET($params,$key = "Your secret salt thingie")
{
$params = decryptStringArray($params,$key);
$param_pairs = explode('&',$params);
foreach($param_pairs as $pair)
{
$split_pair = explode('=',$pair);
$_GET[$split_pair[0]] = $split_pair[1];
}
}
Obviously I replace the "Your secret salt thingie" with other strings. Here is how I use it:
On the page where I need a url:
$url = prepareUrl("http://someurl.com?variable1=1314&variable2=1851&variable3=stringstuff", "algjalgjalgjal");
Then i put the new $url in a href or a tag or something ( i use $smarty templates but that isn't relevant)
On the page someurl.com where i need to decrypt the params i just use:
setGET($_GET['params'],"algjalgjalgjal");
Anyhow this all works fine for me. My only question is, is there anything inherently terrible about this way of doing things? My question is because I posted this as an answer on stack overflow to a question someone asked about hiding their $_GET parameters and it was immediately down-voted. That made me curious about whether it was somehow bad code or insecure in some way.
admin=0toadmin=1then there's a serious problem. – Corbin Jan 9 at 2:16