views:

83

answers:

2

Hi friends,

i need a help,

i was set the file in cron job.

that file is also execution in browser also example : http://example.com/cron.php

how can i restrict in browser excution

Thanks Siva kumar

+4  A: 

The easiest and safest method is to remove it from your web root folders. Stick it somewhere else, have it modify its working directory to being work.

Next best would be to tell your web server not to serve that file. (i.e. .htaccess file for Apache).

You could also detect HTTP Post/Get variables and that would tell you if it is a command line vs web request.

Jacob

TheJacobTaylor
+ if an $argv exists, the script has be called on commandline (so by cron.) (http://us3.php.net/manual/en/reserved.variables.argv.php)
giraff
A: 

You can detect if its cli or not with php_sapi_name or its constant.

if (PHP_SAPI !== 'cli') {
    //not cli
}
OIS