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");
This all works fine for me. Is there anything inherently terrible about this way of doing things? I'm asking this 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=0
toadmin=1
then there's a serious problem. \$\endgroup\$