Is it possible to assign a javascript value to a php variable?

不想你离开。 提交于 2020-01-06 03:03:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!