Tuesday, April 22, 2025

PHP Exec, Html Form

You are advised to check corresponding YouTube video at the end of this article.

form.php


<form action="grabthings.php" method="post">
<label>Command:</label>
<input type="text" name="command">
<br><br>

<input type="submit" value="Submit">
</form>

This HTML form prompts the user to enter a command and submit it to the server using the HTTP POST method. The form sends the user's input as a parameter named "command" to a PHP script called "grabthings.php" for processing.

grabthings.php


<?php 

$get_command = $_POST["command"];

system($get_command);

?>

This PHP script executes a system command that is submitted through an HTML form using the POST method. The command is retrieved from the form input field with the name "command" and is passed as an argument to the system() function.

The system() function is used to execute commands in the system's shell, so the command entered in the form input will be executed on the server.

In PHP, the system() function is used to execute an external command and return the output as a string. It can be used to run various system-level commands such as shell commands, programs, and scripts.

Here are some things that system() can do:

  1. Execute a shell command: You can use the system() function to execute shell commands and get the output as a string. For example, system('ls -l') will execute the ls -l command and return the output as a string.

  2. Run a program: You can also use system() to run an external program, such as a compiled C program or an executable file. For example, system('/usr/bin/myprog') will run the program /usr/bin/myprog.

  3. Call a script: You can use system() to call a script or a batch file. For example, system('python myscript.py') will call the Python script myscript.py.

  4. Redirect output: You can redirect the output of the command to a file or to another command by using shell redirection. For example, system('ls > file.txt') will redirect the output of the ls command to the file file.txt.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...