I just want to pass some query string variables with URL like below. But in this way anyone can see the passing variables. I can use base64_encode()
and base64_decode()
methods but these are also not secure. Because anyone can reverse it. Please help me if anyone have the best solution.
header('Location: http://www.example.com?id='.$id);
or
header('Location: http://www.example.com?name='.$name);
I think this is the best and secure solution for this..
<?php
/*
* PHP mcrypt - Basic encryption and decryption of a string
*/
$string = "Some text to be encrypted";
$secret_key = "This is my secret key";
// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
// Encrypt $string
$encrypted_string = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $secret_key, $string, MCRYPT_MODE_CBC, $iv);
// Decrypt $string
$decrypted_string = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $secret_key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
echo "Original string : " . $string . "<br />
";
echo "Encrypted string : " . $encrypted_string . "<br />
";
echo "Decrypted string : " . $decrypted_string . "<br />
";
?>
Output will be like below:
Original string : Some text to be encrypted
Encrypted string : –LÁ`b]!üƒN{Iç&|«kÿÅLèëɰXp
Decrypted string : Some text to be encrypted