I want to create a simple html page that should contain 2 fields in which the user can write the input. Then I want to have a button that should launch a shell script with the parameters inserted by user in the fields from the webpage.
This is the code behind my webpage:
<html>
<form action="/EMM/script.php" method="get">
Start date: <input type="text" name="sdate"><br>
End date: <input type="text" name="edate"><br>
Recipient adress: <input type="text" name="adress"><br>
<input type="submit" value="Submit">
</form>
</html>
This is how my php script looks like :
#!/usr/bin/php
<?php
$uri = $_SERVER['REQUEST_URI'];
$output = shell_exec('echo $uri > /tmp/test.txt');
echo "<pre>$output</pre>";
?>
I can seem to be able to grab the URL with the needed variables:
http://10.21.289.132/EMM/script.php?sdate=345&edate=er&adress=sdfg
And use these variables in the shell_exec section where I can launch a shell script with them as parameters.
What I have tried was to echo the content of $uri to the /tmp/test.txt and to check after execution. The file is re-created each time, but empty.
In the browser, after I press the submit button I can see URL formed correctly (as shown above) and a blank page is loaded with onle the header of my php script:
#!/usr/bin/php displayed.
Observations:
- my html page and the php script have full rwx rights, are placed in the
/DocumentRoot directory of apache/EMM/
path. - I am not sure at all about my .php syntax, don't know if the scripts needs an interpretor or not.
I do not know if this was the right way to accomplish my task (using html > php > bash). But in this context I don't understand:
- why am I not able to pass the variables from the URL to bash shell using my php script (if I would be able I'd also like some php code to break down the URL into the respective variables sdate , edate and adress.
- why after I press my button a blank page with just the header of my php script is loaded?
Any ideas how to accomplish my task (preferably using html , php and bash shell). ?