LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-10-2012, 06:17 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
simple php ssh script does not display on browser


<html>
<body>
<?php
$var=`ssh 127.0.0.1 ls /`;
print "$var";

?>
<body>
</html>
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
 
Old 09-10-2012, 11:47 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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.
http://php.net/manual/en/function.exec.php

Here is how to run a command via ssh.
http://php.net/manual/en/function.ssh2-exec.php

FYI when posting code please use code tags to preserve formatting.
 
1 members found this post helpful.
Old 09-12-2012, 08:33 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
Code:
ssh joeBloggs@127.0.0.1 ls /
--- rod.
 
Old 09-12-2012, 09:28 AM   #4
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 55
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.
 
  


Reply

Tags
php, ssh



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: Creating a basic simple SSH command to a machine over SSL ? Xeratul Programming 1 01-19-2011 10:24 AM
Web browser display issue with PHP? your_shadow03 Linux - Server 3 02-16-2009 06:26 AM
run shell script bash from browser with php achilles Programming 10 08-02-2007 03:44 PM
Simple PHP Script benrose111488 Programming 7 01-31-2005 01:39 PM
a Simple help on PHP Script Gerardoj Programming 1 10-18-2004 08:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration