-   Programming (
-   -   simple php ssh script does not display on browser (

figure20012 09-10-2012 06:17 AM

simple php ssh script does not display on browser
$var=`ssh ls /`;
print "$var";

ssh promts me to enter my password
when i run script.php on bash it outputs but when i run it on my browser it does not output anything
please help how i can show the results on my browser

michaelk 09-10-2012 11:47 AM

What are you trying to accomplish?

With the information provided I would say that when running from a console your script is being interpreted by bash (or other shell) and not php. Since your script is not proper php syntax it fails when run from the browser.

Here is how to run an external command from php.

Here is how to run a command via ssh.

FYI when posting code please use code tags to preserve formatting.

theNbomr 09-12-2012 08:33 AM

The Web server, and thus your PHP code, runs as a different UID than your own UID. The UID of the web server requires a password to login, if it's UID allows logins at all. Perhaps specify the username for whom you want the directory listing to be done.

ssh joeBloggs@ ls /
--- rod.

YankeePride13 09-12-2012 09:28 AM

PHP is a server side programming language. If you need to enter a password for SSH to work in the browser, then it is already too late because the PHP code has been executed. You'd need to put the password in the code somewhere (preferably in an include with read permissions to only apache or whatever web server you use and root) in order to log in.

In other words, once the server passed the page to the browser, PHP has been completely run. The browser just gets html/xml/javascript that PHP generates.

All times are GMT -5. The time now is 02:12 PM.