问题
I have a (php) array of blowfish encrypted data posted from a form-submit. I have a blowfish algorithm in javascript.
var bf = new Blowfish('12345678901234567');
var ciphertext = bf.encrypt('test data');
alert(ciphertext);
var plaintext = bf.decrypt(ciphertext);
alert(plaintext);
I need to use this javascript blowfish code to decrypt the array of data and save the decrypted data in database.
How can I do this? Can the decrypted value from javascript be assigned to a php variable? Pleas Help...
回答1:
PHP is executed server-side (first, it then send the computed HTML etc. to the client), and JavaScript is executed client-side (last).
It would be possible to assign a PHP value to a javascript variable in a PHP file, for example :
<?php
$myValue = 42;
?>
<script type="text/JavaScript">
var aVariable = <?=$myValue?>;
</script>
You can't do the opposite (what you asked).
What were you trying to do? Maybe we can help you.
回答2:
Dont you just want to use blowfish in PHP? You can use the crypt
function for that.
http://php.net/manual/en/function.crypt.php
回答3:
as TJHeuvel above says you should be capturing the post variables in PHP on the SERVER side not processing with CLIENT side Javascript
来源:https://stackoverflow.com/questions/5581546/is-it-possible-to-assign-a-javascript-value-to-a-php-variable