How can I tell if a Perl script is executing in CGI context?
问题 I have a Perl script that will be run from the command line and as CGI. From within the Perl script, how can I tell how its being run? 回答1: The best choice is to check the GATEWAY_INTERFACE environment variable. It will contain the version of the CGI protocol the server is using, this is almost always CGI/1.1 . The HTTP_HOST variable mentioned by Tony Miller (or any HTTP_* variable) is only set if the client supplies it. It's rare but not impossible for a client to omit the Host header