I want to get a PHP variable from Javascript. so I use help from HTML
我想从Javascript获得一个PHP变量。所以我使用HTML的帮助
<input type="text" value="" name="number1"id="number"style="display:none;">
And then I give the value from Javascript
然后我给出Javascript的值
var c = (Math.floor((Math.random() * 8) + 5)).toString();
document.getElementById("number").value = c;
And finally take it in PHP
最后用PHP。
$number =$_POST["number1"];
Is this dangerous and have any bug possibilities? Thank you
这是危险的并且有任何错误的可能性吗?谢谢你!
3 个解决方案
#1
3
Your code could be safe, it depends on what you do with the data you receive.
您的代码可能是安全的,这取决于您如何处理您收到的数据。
Always keep in mind that you may never trust the user. You could use if-statements to check to see if the input from the user is valid.
永远记住,你可能永远不会信任用户。您可以使用if语句来检查用户的输入是否有效。
#2
1
Validate in PHP is much easier for you.
在PHP中进行验证要容易得多。
See PHP 5 Form Validation at W3Schools
参见W3Schools的PHP 5表单验证
#3
1
Try to use below code. You can use php inside javascript
试着使用下面的代码。可以在javascript中使用php
<script type="text/javascript">
var jvalue = 'this is javascript value';
<?php $abc = "<script>document.write(jvalue)</script>"?>
</script>
<?php echo 'php_'.$abc;?>
#1
3
Your code could be safe, it depends on what you do with the data you receive.
您的代码可能是安全的,这取决于您如何处理您收到的数据。
Always keep in mind that you may never trust the user. You could use if-statements to check to see if the input from the user is valid.
永远记住,你可能永远不会信任用户。您可以使用if语句来检查用户的输入是否有效。
#2
1
Validate in PHP is much easier for you.
在PHP中进行验证要容易得多。
See PHP 5 Form Validation at W3Schools
参见W3Schools的PHP 5表单验证
#3
1
Try to use below code. You can use php inside javascript
试着使用下面的代码。可以在javascript中使用php
<script type="text/javascript">
var jvalue = 'this is javascript value';
<?php $abc = "<script>document.write(jvalue)</script>"?>
</script>
<?php echo 'php_'.$abc;?>