【问题标题】:Securing cron file [closed]保护 cron 文件 [关闭]
【发布时间】:2011-11-29 22:53:22
【问题描述】:

我有一个 cron 文件,monthly.php,我想阻止使用网络浏览器直接访问。它应该只能通过 CPanel cron 访问。

谢谢。

【问题讨论】:

标签: php cron cpanel


【解决方案1】:

不要放在 webroot 下。只需使用命令行 php 程序执行即可。

【讨论】:

    【解决方案2】:

    如果您出于某种原因需要将其放在 webroot 中,请尝试以下操作:Can PHP detect if its run from a cron job or from the command line?

    【讨论】:

      【解决方案3】:

      只需将密钥传递给它即可保护它。并且不要向浏览器报告“缺少密钥参数”,如果密钥不存在,只需 die() 即可。请不要使用参数“key”,使用您自己的参数,例如:

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

      【讨论】:

        【解决方案4】:

        您可以使用 .htaccess 拒绝访问它。或者您可以将其移出htdocspublic_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>
        

        所以只能从服务器请求。

        【讨论】:

        • 是否可以将文件权限设置为640以防止直接访问
        猜你喜欢
        • 2013-06-25
        • 1970-01-01
        • 1970-01-01
        • 2013-05-11
        • 1970-01-01
        • 1970-01-01
        • 2012-04-11
        • 2011-05-19
        • 2021-08-20
        相关资源
        最近更新 更多