rooz
rooz

Reputation: 371

PHP: obfuscate PHP output?

I'm trying to find out if there is a way to obfuscate the PHP output (html stuff).

basically, I have a few hidden inputs and they have some PHP outputs in them...

Example:

<input type="hidden" name="myinput" value="<?php echo $variable; ?>" />

is there any way to obfuscate its value in the users browser but still readable server side so I can pass the input value between pages?

any suggestion and help would be appreciated.

EDIT: I did it like this:

$string = "my string to be be encrypted goes here";
$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 />\n";
echo "Encrypted string : " . $encrypted_string . "<br />\n";
echo "Decrypted string : " . $decrypted_string . "<br />\n";

Upvotes: 0

Views: 306

Answers (1)

David J Eddy
David J Eddy

Reputation: 2037

Instead of returning the values as part of the form field; do not send them data at all! Save the data to a database table and link to the current user. Link the data with the user via any number of methods (User id, cookie, session, etc). when the form is submitted retrieve the secret and execute your business logic.

Side note: If you want the data to be secure you want to encrypt it, not hash, not encode; encrypt.

Upvotes: 1

Related Questions