daQuincy daQuincy - 1 month ago 16
PHP Question

Getting user input using PHP

Working on a simple project where I can type

192.168.x.xx/?$n
into the address bar of the browser, and then the Raspberry Pi will send a pwm signal (using WiringPi library) that is equivalent to the variable
$n
to a LED. I am just starting with PHP, that's why I need help here. What I have in mind now:

<?php
exec("gpio mode 1 pwm");
//declare $n as a variable (integer maybe)
//$n = the user input value from browser (I only know $_GET, pretty sure it's not this right?)
exec("gpio pwm 1 "+$n);
?>


Will appreciate any help and pointers.

Answer

you have to enter data through URL like this...

192.168.x.xx/?data=n                //n is of type int


//php script
<?php
$n=$_GET['data'];
exec("gpio mode 1 pwm");
//declare $n as a variable (integer maybe)
//$n = the user input value from browser (I only know $_GET, pretty sure it's not this right?)
exec("gpio pwm 1 ".$n);
?>