Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML to Javascript to PHP. Is this 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 this dangerous and have any bug possibilities? Thank you

like image 910
Elbert Avatar asked Jan 28 '16 06:01

Elbert


3 Answers

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.

like image 111
Mister Verleg Avatar answered Oct 16 '22 14:10

Mister Verleg


Validate in PHP is much easier for you.

See PHP 5 Form Validation at W3Schools

like image 1
Khairoul Ikhwan Avatar answered Oct 16 '22 13:10

Khairoul Ikhwan


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;?>
like image 1
Dhaval Patel Avatar answered Oct 16 '22 13:10

Dhaval Patel