Google Bot 可以执行 PHP 脚本
我有一个 CRON 作业 php 脚本,是我不久前刚刚设置的。但是,我注意到 PHP 文件已执行(没有激活 cron 作业)。看来这是在 Google Bot 抓取该文件时发生的,因为我注意到以下引擎访问了我的页面:
http://www.google.com/bot.html
我的问题是:
1)是否有可能通过抓取我的网页,它可以执行脚本?
2) 如何对 Google“隐藏”CRON 文件?
3)将此文件放在 public_html 目录之外的其他位置是否明智?
非常感谢!
I have a CRON job php script that I just set up not too long ago. However, I noticed that the PHP file executed (without the cron job activating). It appears that it happened when a Google Bot crawled the file, because I noticed that the following engine visited my page:
http://www.google.com/bot.html
My question is:
1) Is it possible, that by crawling my webpage, it could have executed the script?
2) How can I "hide" the CRON file from Google?
3) Would it be smart to place this file in somewhere other than my public_html directory?
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
1) 当然是
2) 参见 robots.txt (http://www.searchtools .com/robots/robots-txt.html)
3) 是的。但如果由于某种原因你依赖于通过 http 守护进程调用它,你可以使用一个小技巧。
例如。第一行代码:
在您的 crontab 中:
http://server.tld/file.php?execute =1
1) of course it is
2) see robots.txt (http://www.searchtools.com/robots/robots-txt.html)
3) yes. but if for some reason you depend on calling it via a http daemon you can use a little trick.
eg. first line of code:
in your crontab:
http://server.tld/file.php?execute=1
1) 如果文件放置在公共网络目录中,那么是的,它可以由 Googlebot(或任何其他访问者)执行
2) 您可以在 robots.txt。如果您这样做,任何普通用户仍然可以通过访问来执行它。
3)是的。
1) If the file is placed in a public web directory, then yes, it could be executed by Googlebot (or any other visitor)
2) You could add a Disallow clause for it in your robots.txt. Any regular user can still go and execute it by visiting if you do this.
3) Yes.
您还可以使用 php-cli。定义是否是 cron 作业:
然后在 php 文件中:
You can use also php-cli. Define if it is cron job:
Then in php file:
Runifus 上面的答案为我解决了这个问题,但是 Cron 作业命令行不适用于 ?在 url 中传递查询字符串,正如我在这里学到的: Cron Jobs 调用带变量的 PHP 脚本
应该是这样的:
php 条件也缺少右括号
Runifus' answer above solved it for me, however the Cron job command line does not work with the ? in the url to pass the querystring as I learnt here: Cron Jobs calling a PHP script with variables
It should be like so:
also the php condition is missing a closing parenthesis