【发布时间】:2011-11-29 22:53:22
【问题描述】:
我有一个 cron 文件,monthly.php,我想阻止使用网络浏览器直接访问。它应该只能通过 CPanel cron 访问。
谢谢。
【问题讨论】:
我有一个 cron 文件,monthly.php,我想阻止使用网络浏览器直接访问。它应该只能通过 CPanel cron 访问。
谢谢。
【问题讨论】:
不要放在 webroot 下。只需使用命令行 php 程序执行即可。
【讨论】:
如果您出于某种原因需要将其放在 webroot 中,请尝试以下操作:Can PHP detect if its run from a cron job or from the command line?
【讨论】:
只需将密钥传递给它即可保护它。并且不要向浏览器报告“缺少密钥参数”,如果密钥不存在,只需 die() 即可。请不要使用参数“key”,使用您自己的参数,例如:
http://myscript.com/monthly.php?mycomplexkeyname=ksldhfguorihgiauzsiludrfthgo45j1234134
【讨论】:
您可以使用 .htaccess 拒绝访问它。或者您可以将其移出htdocs 或public_html 目录。
<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>
所以只能从服务器请求。
【讨论】: