faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 8 people (100%) answered Yes
Recently 8 of 8 people (100%) answered Yes

Entry

How can I tell if a script is running from the command line (cli) or in a browser?

Mar 19th, 2008 22:35
ha mo, Philip Olson, Paul Meier, Gary Czychi,


Use the PHP function php_sapi_name() so for example:
<?php
if (php_sapi_name() == 'cli') {
    echo "You are using cli";
} else {
    echo "You are using something other than cli";
}
?>
More information exists in the PHP manual:
  http://www.php.net/php-sapi-name
http://www.tantofa.com
http://www.fantofa.com
http://www.mantofa.com
http://www.tanpola.com
http://www.tampola.com
http://www.yamot.com
http://www.mozmar.com
http://www.templatestemp.com