... or the other way around, is there any way to know if a php script is running inside a web server?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
You could check the $_SERVER variables ... such as:
This will be empty if it is not executed through a web server.
I wrote a small php script that only contained this line:
When I executed it in the commandline, this was part of my output:
Running the same thing on the webserver gave me this:
Of note are these vars, which might end up being the most useful:
http://www.php.net/manual/en/function.php-sapi-name.php
Typically, when running in CLI mode, the superglobals
$argv
and$argc
will be set, and many of the typical contents of$_SERVER
(e.g. request method) won't be available. In addition, pre-defined console streams such asSTDIN
,STDOUT
andSTDERR
will be set up.