How can I determine if a script was called from the command line or as a cgi script?

后端 未结 3 1050
天命终不由人
天命终不由人 2020-12-06 12:21

I have a script that I wrote that can either be used on the command line or as a CGI script, and need to determine how the script was called so I can output a content-type h

3条回答
  •  感动是毒
    2020-12-06 12:36

    According to the CGI specification in RFC3875 (section 4.1.4.), the GATEWAY_INTERFACE environment variable would be the authoritative thing to check whether you are running in a CGI context:

    4.1.4. GATEWAY_INTERFACE

    The GATEWAY_INTERFACE variable MUST be set to the dialect of CGI being used by the server to communicate with the script.

提交回复
热议问题