note 93970 added to function.php-sapi-name
| From: | clancyhoodatgmaildotcom at osu1 dot php dot net | Date: | Fri, 09 Oct 2009 01:58:45 +0000 |
| Subject: | note 93970 added to function.php-sapi-name | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161579@lists.php.net to get a copy of this message | ||
good call by michal at roszka dot pl:
<?php
define('PHP_CXT_HTTP', 1);
define('PHP_CXT_TERM', 2);
define('PHP_CXT_CLI', 4);
define('PHP_CXT_CGI', 8);
define('PHP_CXT_MOD', 16);
$X = isset($argc) ? PHP_CXT_TERM : PHP_CXT_HTTP;
switch(substr(PHP_SAPI, 0, 3)){
case 'cgi':
$X = $X | PHP_CXT_CGI;
break;
case 'cli':
$X = $X | PHP_CXT_CLI;
break;
default:
$X = $X | PHP_CXT_MOD;
}
define('PHP_CXT', $X);
echo 'This script was '.(PHP_CXT & PHP_CXT_HTTP ? '' : 'not
')."initiated via a HTTP request <br/>\n";
echo 'This script was '.(PHP_CXT & PHP_CXT_TERM ? '' : 'not
')."initiated via a terminal <br/>\n";
echo 'PHP is '.(PHP_CXT & PHP_CXT_CGI ? '' : 'not
')."running as CGI <br/>\n";
echo 'PHP is '.(PHP_CXT & PHP_CXT_CLI ? '' : 'not
')."running as CLI <br/>\n";
echo 'PHP is '.(PHP_CXT & PHP_CXT_MOD ? '' : 'not
')."running as a server module <br/>\n";
?>
Tested via http and cmdline on own box (cli) and remote cgi-only host.
However, isset($argc) is a very weak test, and this need be called at the very beginning of a script
tree. If anyone has a better method of orientating oneself in an arbitrary environment *please do*
correct me.
----
Server IP: 80.64.47.13
Probable Submitter: 89.130.23.72
----
Manual Page -- http://www.php.net/manual/en/function.php-sapi-name.php
Edit -- https://master.php.net/note/edit/93970
Del: integrated -- https://master.php.net/note/delete/93970/integrated
Del: useless -- https://master.php.net/note/delete/93970/useless
Del: bad code -- https://master.php.net/note/delete/93970/bad+code
Del: spam -- https://master.php.net/note/delete/93970/spam
Del: non-english -- https://master.php.net/note/delete/93970/non-english
Del: in docs -- https://master.php.net/note/delete/93970/in+docs
Del: other reasons-- https://master.php.net/note/delete/93970
Reject -- https://master.php.net/note/reject/93970
Search -- https://master.php.net/manage/user-notes.php