0

I have an apache server on a raspberry pi. I have a basic program where the user inputs a string into an html form box. Clicking submit sends the entry to a php file, which then calls a shell script, and passes the entry as a prompt. If you look at the php below, it has a variable with the user input, and it calls the shell file main.sh. How can I provide the shell program that variable as an input. I have looked at proc_open, but haven't been able to get it to work. Thanks Index.html:

    <!DOCTYPE html>
<html>
<head>

</head>
<body>
    <form action="script.php" method="post" enctype="multipart/form-data">
    Address: <input type="text" name="Address" value=""><br>
    <input type="submit" value="Upload" name="submit">
    </form>
</body>
</html>

script.php:

<?php
if(isset($_POST["submit"])) {
    if($_POST['Address'] != "")
    {
        $entry = $_POST['Address'];
        $output  = shell_exec ("./main.sh");
        echo $output;
    }
}
?>

and finally the shell file: main.sh:

echo -n "Do you like pie (y/n)? "
read answer
if echo "$answer" | grep -iq "^y" ;then
    echo Yes
else
    echo No
fi
figbar
  • 714
  • 12
  • 35

1 Answers1

3

you can pass variable to shell script as follows

$output = shell_exec("./main.sh $entry");

and in shell script , Add x = $1 . $x would be variable, with your user input value.

Look for this post for further details https://stackoverflow.com/a/19460686/3086531

bhar1red
  • 440
  • 3
  • 10