Alex Rivera | Logout

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

Asked 2012-08-24T03:04:54.657
11

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.

Edit
Report

1 Answer

11

The following solution is easy enough to implement and is strong enough unless you deal with very sensitive data such as credit-cards information or NASA algorithms...

When you send the parameter via. GET - add a hash value along with it, for example:

$parameter = "abc"; //The parameter which you'll pass as a GET parameter
$salt = "cV0puOlx";
$hashed = md5($salt.$parameter);//A hash that you'll pass as well
header("Location: http://www.yourdomain.com?param=$parameter&hash=$hash");

Then when you read the parameters, check that the hash is a valid one:

$parameter  = $_GET['param'];
$hash = $_GET['hash'];
$salt = "cV0puOlx";
$hashed = md5($salt.$parameter);
//now you check:
if ($hash === $hashed){
   //everything's fine - continue processing
}
else{
  // ERROR - the user tried to tamper with your parameter
  // show error-message and bail-out
}
answered 2012-08-24T03:47:28.133

Your Answer