开发者

Securing cron file [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

I've have a cron file, monthly.php and I want 开发者_StackOverflow中文版to prevent direct access using web browser. It should be accessible only through CPanel cron.

Thanks.


Don't put it under the webroot. Just execute it using the command line php program.


You can use a .htaccess to deny access to it. Or you can just move it out of the htdocs or public_html directory.

<Files "cron.php">
  Order deny,allow
  Allow from name.of.this.machine
  Allow from another.authorized.name.net
  Allow from 127.0.0.1
  Deny from all
</Files>

So it can only be requested from the server.


If you, for some reason, need to put it in a webroot, try the following: Can PHP detect if its run from a cron job or from the command line?


Just pass in a key to it to protect it. And don't report "Key parameter is missing" to the browser, just die() if the key is not there. And please, dont use the parameter "key", use something of your own like:

http://myscript.com/monthly.php?mycomplexkeyname=ksldhfguorihgiauzsiludrfthgo45j1234134
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜