Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP : Form example which will encrypt query string (GET) (data hiding rather than security)

I intend to use GET for my form but would like to encrypt the values in the query string so that users are not able to change it. (not for security, but for data hiding purposes)

I came across a couple of websites which explained encryption, but it is not clear to me how to implement it once the user presses the submit button. Ex: http://myscriptlibrary.wordpress.com/2010/04/14/how-to-encrypt-query-string-in-php/

Is there an example which could show this?

Thanks.

like image 302
SEU Avatar asked Aug 24 '12 03:08

SEU


2 Answers

From my understanding of the link that you provided. You want to encrypt the GET variables, or at least obfuscate them.

The best and easiest way that this could be done is using base64_decode/encode For example to encode the string you would do something like:

$link = "http://www.example.com/?item=".urlencode(base64_encode("user-data"));

$link would look something like http://www.example.com/?item=rklgEwkelnf%3D%3D, but to translate the seemingly garbled (base64ed) text into something usable you would use:

foreach($_GET as $loc=>$item)
    $_GET[$loc] = base64_decode(urldecode($item));

Then you can freely use the $_GET variable as you normally would.

like image 141
Glenn Dayton Avatar answered Sep 18 '22 10:09

Glenn Dayton


The accepted answer here doesn't provide any real protection. You can just take the encoded parameters and put them into an online base64_decode and it shows the values as if you have just passed them directly!

The other answer uses $hash as a pass through value but that value hasn't been defined only $hashed.

like image 26
HeavyHead Avatar answered Sep 18 '22 10:09

HeavyHead