是否可以将javascript值分配给php变量?

时间:2011-04-07 13:05:30

标签: php javascript blowfish

我有一个(php)数组的河豚加密数据从表单提交发布。我在javascript中有一个blowfish算法。

var bf = new Blowfish('12345678901234567');
var ciphertext = bf.encrypt('test data');
alert(ciphertext);
var plaintext = bf.decrypt(ciphertext);
alert(plaintext);

我需要使用这个javascript blowfish代码来解密数据数组并将解密后的数据保存在数据库中。

我该怎么做?可以将来自javascript的解密值分配给php变量吗? 请求帮助...

3 个答案:

答案 0 :(得分:3)

PHP在服务器端执行(首先,它然后将计算的HTML等发送到客户端),JavaScript在客户端(最后)执行。

可以将PHP值分配给PHP文件中的javascript变量,例如:

<?php
    $myValue = 42;
?>
<script type="text/JavaScript">
    var aVariable = <?=$myValue?>;
</script>

你不能做相反的事(你提出的问题)。

你想做什么?也许我们可以帮助你。

答案 1 :(得分:1)

你不想在PHP中使用blowfish吗?您可以使用crypt功能。

http://php.net/manual/en/function.crypt.php

答案 2 :(得分:0)

如上面的TJHeuvel所说,您应该在SERVER端捕获PHP中的post变量,而不是使用CLIENT端Javascript处理

相关问题