How to tell if PHP is running from the command line (CLI) or the web.

if(isset($_SERVER['REMOTE_ADDR']))
{
    die();
}

If you have a script that needs to run from the command line (say, via cron), but for some dumb reason needs to reside in a publicly accessible location (e.g. via the web), use the above code at the very start of your script.  The only time that particular variable exists is when someone is connecting over the web.  Command line execution doesn't create it.

 

October 6, 2011 at 10:26pm / PHP 

Comments On This Entry

test

test @ 08:20:56 PM, Sunday, October 9, 2011

Wowza, problem solved like it never hppaened.

Chyna @ 10:13:36 PM, Saturday, October 22, 2011

Compose New Blog Comment
    required = required field         warning HTML and URL's are not allowed

[back to main]