Executing system commands through PHP code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Newfriend
Forum Newbie
Posts: 2
Joined: Thu May 18, 2006 2:35 am

Executing system commands through PHP code

Post by Newfriend »

I have problem in executing exec() on browser.

I could run a php program that includes exec() using command line execution of PHP, the same program is not working from the browser.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Executing system commands through PHP code

Post by Chris Corbyn »

Newfriend wrote:I have problem in executing exec() on browser.

I could run a php program that includes exec() using command line execution of PHP, the same program is not working from the browser.
On command line PHP uses the userid of the person executing the code and thus, has those privileges. In a browser PHP runs under the userid of the HTTPd user and thus only has those privileges. Basically, check your permissions on the executable file ;)
Newfriend
Forum Newbie
Posts: 2
Joined: Thu May 18, 2006 2:35 am

Post by Newfriend »

I checked out all those permission. Its proper.

I am giving u a smaple code where I exactly have the problem.

<?

exec("iptables -L",$out,$ret)

if($ret==0)
{
for($i=0;$i<count($out);$i++)
print(" $out[$i] ");
}

?>

This code is listing all the rules in iptables when executed from command prompt. But no output from browser.

I am working at root, I have all privilages.
Please help me.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

This would imply that your webserver also runs under the root account... which is just really wrong..
Post Reply