I want to get a PHP variable from Javascript. so I use help from HTML
<input type="text" value="" name="number1"id="number"style="display:none;">
And then I give the value from Javascript
var c = (Math.floor((Math.random() * 8) + 5)).toString();
document.getElementById("number").value = c;
And finally take it in PHP
$number =$_POST["number1"];
Is this dangerous and have any bug possibilities? Thank you
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.
Validate in PHP is much easier for you.
See PHP 5 Form Validation at W3Schools
Try to use below code. You can use php inside javascript
<script type="text/javascript">
var jvalue = 'this is javascript value';
<?php $abc = "<script>document.write(jvalue)</script>"?>
</script>
<?php echo 'php_'.$abc;?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With