vk | post sharer script php | how to change mysql to mysqli | how to delete a cookie using setcookie()
 


 

Determine PHP script Invocation: CLI or by the Web Server



In most cases you can distinguish if a PHP script was invoked from the command line (or Cron) or by the web server, using php_sapi_name().

php_sapi_name() will return cli on CLI (or Cron) invocation and some other values on invocation by Web Server (e.g. apache2handler for Apache).

Example

A simple example:

<?php
if(php_sapi_name() == 'cli') {
	// your code here
} else {
	// your code here
}
?>

Your comments are welcomed!

References

From PHP manual

Εγγραφή!
Sign-up for our free email newsletter. Get updates when new tutorials and tips are published. You can unsubscribe anytime with a click.

Your comments are welcomed!

This site actively encourages commenting on any post. Comments are not pre-moderated, but this community does not tolerate direct or indirect attacks, name-calling or insults. Please, read terms of use and Comment Policy at privacy policy.

More tips