Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIX Terminal 5

Status
Not open for further replies.

peacecodotnet

Programmer
Joined
May 17, 2004
Messages
123
Location
US
I want to make a live UNIX terminal using PHP. Can you send commands to UNIX through PHP? If so, how can you get UNIX's response?

For example, I want there to be a giant text area on the top of the page and a little text box on the bottom for you to put in commands. When you put in a command, the PHP script puts that command in the text area, then sends that command to UNIX, gets the response, and puts the response one line underneath the command in the text area.

Thanks so much in advance.

Peace out,
Peace Co.
 
PHP is a server side script, therefore even if u manage to communicate to UNIX OS, only the server's Unix can be contacted...

Known is handfull, Unknown is worldfull
 
vbkris has the answer.
You cannot create a "live" terminal as there is no connection between the browser and the server beyond the transfer of the request and the response. It's like a phone call that ended and both parties hung up.
However, you can simulate the functionality - the only difference is that there is no connection when the "terminal" (browser) is idle. You can send commands and receive the output. You would have to keep the environment information (path etc.) in a session.
Warning:
Executing shell commands using system(), exec() etc. through the Web is not advisable. There are some points to consider.
1. The user that Apache/web-server runs as will execute the commands. You can't "log" in as yourself, such terminal like communication is not possible.
2. Predefined, very specific UNIX commands in the PHP code can be safe if porperly used. The possibility to type in anything through a browser and have it executed on the system scares me. What about:
Code:
rm -Rf *

The only safe place to do that would be your localhost, but why do it there? You have a shell. I strongly advise against this.
 
Do you want to do this because your ISP wont allow you to the command prompt ?. If it is they should provide you woth a control panel.
 
Others seem to thing it could not be done - I agree with the assesment as far as what is feasible for the average user, but I disagree as to whether or not it is possible to maintain a live session.

PHP allows you to run programs from the terminal, but does not allow you to maintain the connection to the command line, or maintain state of these called commands. You can however create a utility that resides on the unix machine that would maintain this state for you. The PHP piece would simply be the front end to this utility. The utility could handle the state settings, and everything else. Think of it as a console proxy.

I would not suggest doing this, but it is possible.
 
If you were to try the proxy approach something would have to run up a series of process on the server machine to attach to and you would have to re-attach to the same process every time you entered a command so your state and environment were maintained.
This process would have to emulate the command interpreter (ie the shell).
If your realy serious about this I'm sure that you can get Java applets that run in the browser and maintain the connection to the Unix machine for you.
 
I have to apoligize. I made that same post in the Javascript thread, then copied it here, but I forgot to take out the "live" part.

Thanks to everyone for answering, but DRJ478 is the only one who really helped me. I think I'll use the system() function and then just keep passing a variable to the same page and adding my commands and UNIX's responses to it, which I found out can be done with the system() function. Thanks again.

Peace out,
Peace Co.
 
And, to answer ingresman, I want to make the UNIX terminal because everyone in the UNIX discussion thread is really vague and they answer me like I'm an expert at it! Therefore, I'm just gonna test things out myself...carefully.

Peace out,
Peace Co.
 
i'd persoanally look at fsockopen a basic telnet client is possible.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top