echo javascript表单值

时间:2013-02-13 04:34:46

标签: php javascript

我有这个脚本。

<head>
<script type="text/javascript" src="sha1.js"></script>

</head>
<body>
<?php
$A= 'TEST01';
$B= '059B8125F';
$C= '20061123_003';
$D= '100.00';
$E= '50126';

?>
<form name="checkout" method="post" action="">
<input type="hidden" name="A" value="<?php echo $A; ?>" />
<input type="hidden" name="B" value="<?php echo $B; ?>" />
<input type="hidden" name="C" value="<?php echo $C; ?>" />
<input type="hidden" name="D" value="<?php echo $D; ?>" />
<input type="hidden" name="E" value="<?php echo $E; ?>" />
</form>

<script type="text/javascript" language="javascript">
var str = "##" + form.A.value.toUpperCase() + "##" + form.B.value.toUpperCase() + "##" + form.C.value.toUpperCase() + "##" + form.D.value.toUpperCase() + "##" + form.E.value.toUpperCase() + "##";

form.SIGNATURE.value = hex_sha1(str);
</script>


</body>

我的问题是,如何在PHP中显示SIGNATURE值?我想在回声中显示它。有可能吗?

谢谢大家

1 个答案:

答案 0 :(得分:0)

PHP的sha1函数可用于此。

这应该从php-side计算。

<head>
<script type="text/javascript" src="sha1.js"></script>

</head>
<body>
<?php
$A= 'TEST01';
$B= '059B8125F';
$C= '20061123_003';
$D= '100.00';
$E= '50126';

$hash_str = "##" + strtoupper($A) + "##" + strtoupper($B) + "##" + strtoupper($C) + "##" + strtoupper($D) + "##" + strtoupper($E) + "##";

$signature = sha1($hash_str);

echo $signature;
?>

<form name="checkout" method="post" action="">
<input type="hidden" name="A" value="<?php echo $A; ?>" />
<input type="hidden" name="B" value="<?php echo $B; ?>" />
<input type="hidden" name="C" value="<?php echo $C; ?>" />
<input type="hidden" name="D" value="<?php echo $D; ?>" />
<input type="hidden" name="E" value="<?php echo $E; ?>" />
<input type="hidden" name="SIGNATURE" value="<?php echo $signature; ?>" />
</form>

</body>