HTML for Javascript for PHP. This is dangerous?

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 it dangerous and has any errors? thank you

+6
source share
3 answers

Your code may be safe, it depends on what you do with the data you receive.

Always remember that you never trust the user. You can use if-statements to validate data entry.

+3
source

Checking for PHP is a lot easier for you.

See PHP 5 Form Validation in W3Schools

+1
source

Try using the code below. 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;?> 
+1
source

All Articles