I am a complete beginner in PHP. I am trying to create a HTML/ PHP Script that will use the user input from an HTML form and than use php shell_exec to search for files with that input using the "find /var/www -Name " command.
I know how ro run a simple script with PHP, but I have no idea how do do that with user Input... Eg: "
<?php
if (isset($_POST['button']))
{
exec('test.sh');
}
?>
<html>
<body>
<form method="post">
<p>
<button name="button">Run Script</button>
</p>
</form>
</body>
"
This is how far I've got. I've decided two make to files, one HTML, the second one the PHP script:
search.html
<html>
<body>
<form action="search.php" method="post">
keyword: <input type="text" name="keyword"><br>
<input type="submit">
</form>
</body>
</html>
php script: search.php
<html>
<body>
<?php shell_exec('find /var/www -Name "keyword"') $_POST["keyword"]; ?>
</body>
</html>
This should do the trick :
BEWARE: it is a bad idea to use such a command, because you are using user input directly, user can run any kind of command on the server.
For example, if a user type
"; rm -rf /var/www;echo "
as search, it will delete the whole content of your/var/www
folder. You'd better implement a php function that will do the same thing as your find command.However, you MUST ALWAYS do sanitize any user input, everything that comes from the outside world is evil..