shell_exec() and exec() not working in PHP

前端 未结 2 757
既然无缘
既然无缘 2021-01-15 02:08

Like many others I have problem with shell_exec() function in PHP. I have safe mode disabled and disabled_functions deleted from php.ini.

If I run php script from te

相关标签:
2条回答
  • 2021-01-15 02:24

    Progamming language PHP allows one to limit executing of external commands via configuration directive safe_mode_exec_dir. This directive should contain full path to a directory conatining programs which PHP script can run. If the script tries to execute a command not located in this directory, the command is not executed. This configuration directive is active only if safe mode is enabled, which means more and sometimes unwanted restrictions to users. PHP has no known possibility to limit executing of external commands with disabled safe mode. Teherefore, here is a patch adding special directive exec_dir straightly into PHP. This directive is very similar to safe_mode_exec_dir, but safe mode has not to be enabled.

    This patch limits or corrects the behavior of these functions:

    exec()
    passthru()
    proc_open()
    shell_exec()
    system()
    popen()
    is_executable() 
    

    The patch was created for purposes of limit execution of external commands of users on a multidomain apache server, first for PHP version 4.2.1. The patch was sent to PHP developers so it could be a part of PHP, but no one of PHP developers was interested in. On the other side, some PHP users wanted this patch, therefore this site was created.

    0 讨论(0)
  • 2021-01-15 02:39

    Your command line (CLI) PHP might be using a different working directory and/or path than the CGI one. Try defining the working directory (containing the lp command) explicitly with chdir() before calling shell_exec().

    0 讨论(0)
提交回复
热议问题