开发者

Linux/PHP Question

I'm a pretty Huge n00b when it comes to Linux

exec ('whoami', $output, $return);
echo $return;  

// Outputs 127 Which means the command is not executing. I can get it to execute开发者_运维百科 when I root into the server.

Any help would be greatly appreciated!


If you try this:

<?php
exec('whoami');
?>    

you should be presented with PHP's username.. If you try this:

<?php
exec('whoami', $output, $return);
print_r($output);
?>

you should see that $output is an array containing anything the shell output.

The return value, according to the PHP manual, "return status of the executed command will be written to this variable." - is that what you want?


127 exit status is indicative of a missing command. Perhaps whoami is not on the system or maybe your web server configuration has you jailed in some way or you are being restricted via safe_mode/open_basedir.

To verify you can try running:

exec('which whoami', $output, $return);
print_r($output);
echo $return;

If you are presented with an empty array and a return code of 0, then the whoami executable is currently inaccessible from your web server/PHP setup.

To check safe_mode, open_basedir settings, call phpinfo.


Why not just do something like:

<?php

$var = `whoami`;

echo $var;

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜