php shell_exec

Hey guys i've recently been getting into php programming and i became thinking was it possible to create a php script that would allow you to run a terminal from the browser page?

All i've pretty much got so far is:

$var = $_GET['command'];

$output = php shell_exec($var);
echo $output;

However it is extremely limited in its applications as it can only run one command at time, doesn't report shell errors back to $output. Lacks changing directory function.

I've been looking around but so far i haven't been able to find anything beyond doing simple 1 line commands :frowning:

Is it even possible to create a more robust terminal session in php???

Note: I'm not to worried about security as it will just be ran on my Home LAN in which the server shouldn't be accessed externally.

Give me your honest thoughts,

http is a stateless protocol so you really cannot run a terminal but you can simiulate a shell by running commands via php.

What stateless means is that every time you run a PHP script, it loads, runs, and quits by the time the user gets it. Each time is a fresh start.

php does have a directory-changing function -- chdir() -- but since the script quits every time it finishes it won't stay where you put it.

If you want a remote shell, how about ssh?

Perhaps one of these projects may suit your needs. If not, they may help you in your search.

Anyterm - Introduction
Index of /software/ajaxterm

Regards,
Alister

Hey thanks for the replies guys, i've worked on it some more and have figured out a way around the 'change directory' problem by recording the working directory it currently is in and changing the directory at the start of each script so its in the correct one :slight_smile:

However currently there are two problems (so far i can work out).

  1. The php script doesn't get the errors when the command isn't put in correctly

  2. Currently unable to do 'multi-line' tasks.

@Corona688

The whole idea of this script was to get around the need for SSH. As i am currently hosted with JustHost, and if i can get this working fully i shan't have to pay extra for SSH access :slight_smile: . I will of course implement security if i put it online (thats no problem for me) i am just unfamiliar with shell_exec and haven't been able to find more extensive documentation on it.