panidarapu
panidarapu

Reputation: 9097

i want to run a file using cron job not in a browser

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

Upvotes: 0

Views: 143

Answers (2)

OIS
OIS

Reputation: 10033

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

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

Upvotes: 0

TheJacobTaylor
TheJacobTaylor

Reputation: 4143

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

Upvotes: 4

Related Questions