How to check with PHP if the script is being run from the console or browser request?

后端 未结 6 1623
孤街浪徒
孤街浪徒 2021-02-02 05:58

I tried things like $_ENV[\'CLIENTNAME\'] == \'Console\' but that seems to work on only certain OS\'s (worked in windows, not linux).

I tried !empty($_ENV[\'SHELL\']) b

6条回答
  •  Happy的楠姐
    2021-02-02 07:00

    One solution is to check whether STDIN is defined:

    if (!defined("STDIN")) {
        die("Please run me from the console - not from a web-browser!");
    }
    

提交回复
热议问题