开发者

php system(); function is losing args when run through cgi but not from cli

When calling a php file which contains:

<?php system('/bin/sh /usr/local/bin/myScript.sh '.'myArg'); ?>

from cli through php myScript.php everything runs fine but when doing it through cgi, opening the url in the browser 开发者_开发问答(apache in the background) myArg string gets lost. Does anyone knows what could be failing?

PD: myScript.sh is just an

echo "$# $*" >> /tmp/foo.txt  

so a tail /tmp/foo.txt shows everything works fine from cli but not from apache's cgi. Do I need any extra configuration in php.ini? Do i need anything special in my apache alias file? Is it boodoo?


If your code is as you listed it above, 'myArg' will not be lost. However, if you are populating the argument dynamically, you will need to ensure that you collect the argument in a way that works appropriately for the calling method.

When you execute the script via a browser, you can collect arguments via $_REQUEST, $_GET, or $_POST. When you execute the script via CLI, the arguments will be found in $argv.

If you have verified that you get the correct value for the argument, the next step is to check permissions. Ensure that the CLI user has permissions to execute the command with the argument specified.


Make sure the user that runs apache has a shell in /etc/passwd. Default user is nobody.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜