Executing unix shell commands using PHP

前端 未结 7 614
再見小時候
再見小時候 2020-12-16 01:17

A text box will be used to capture the command. I\'ve been told that I have to use the exec() function to execute UNIX shell commands.

Something like th

7条回答
  •  别那么骄傲
    2020-12-16 02:10

    exec?

    system?

    shell_exec?

    passthru?

    Backticks?

    Pfah!

    Real developers use proc_open! It has the major and distinct advantage of giving you three PHP streams to feed data into the process, and read both stdout and stderr. This is something that the other process execution functions simply don't do well.

    It comes at the small cost of some boilerplate code, so it's a bit more verbose. I consider the trade-off to be excellent.

    Oh, and running arbitrary commands from your users is perhaps one of the greatest security risks that you could ever conceive of, but I kind of assume you know this by now.

提交回复
热议问题