I have a E-mail schedule runs everyday on php page using cron jobs. The php code workds fine when i run the page using a link.
我有一个电子邮件计划每天在PHP页面上使用cron作业运行。当我使用链接运行页面时,PHP代码工作正常。
Now when I run the php script using cron jobs, it also works fine but when I put some query the cron jobs won't understand the link.
现在,当我使用cron作业运行php脚本时,它也可以正常工作,但是当我提出一些查询时,cron作业将无法理解链接。
for example: http://www.wetube.org/cron.php?id=01001
so now if I try to run this everyday using cron job it's doesn't work.
例如:http://www.wetube.org/cron.php?id = 01001所以现在如果我尝试使用cron job每天运行它,它就不起作用了。
But if we just erase the query it works fine. Do you guys know any code which makes this link work in cron job?
但是,如果我们只是擦除查询它工作正常。你们知道任何使这个链接在cron工作的代码吗?
2 个解决方案
#1
37
Cron runs commands as they would be ran via the shell, so running PHP would use local paths.
Cron运行命令,因为它们将通过shell运行,因此运行PHP将使用本地路径。
You need to use a command like:
您需要使用如下命令:
php /home/USER/public_html/cron.php
Or if including the query string is necessary, use cURL instead (if it's installed):
或者,如果需要包含查询字符串,请改用cURL(如果已安装):
curl http://www.wetube.org/cron.php?id=01001
You might want to look at not exposing your cron scripts to the internet - move them to outside your web directory because if someone finds it they can constantly reload it to spam your cron scripts (i.e. sending lots of emails)
您可能希望不要将您的cron脚本暴露给互联网 - 将它们移到您的网络目录之外,因为如果有人发现它,他们可以不断地将其重新加载到您的cron脚本垃圾邮件(即发送大量电子邮件)
#2
7
I would add hash like
我会添加哈希像
curl http://www.wetube.org/cron.php?id=01001&hash=cm349ucKuc023b2ynGyv23ycr23
and in php file
并在PHP文件中
if(isset($_GET['hash']) && $_GET['hash']=='cm349ucKuc023b2ynGyv23ycr23'){
....
stuff to do
....
}
*you can even add specific time/date check when it should be run.
*you can check IP
*generate sha512 (I would recommend) hashes in both cron and php file with the same salt and maybe even time and then check if they are the same - it would be impossible for a hacker to recreate it - except if he somehow gets your original hash setup
*您甚至可以在应该运行时添加特定的时间/日期检查。 *你可以检查IP *生成sha512(我建议)使用相同的盐在cron和php文件中进行哈希,甚至是时间然后检查它们是否相同 - 黑客不可能重新创建它 - 除非是他以某种方式得到你原来的哈希设置
#1
37
Cron runs commands as they would be ran via the shell, so running PHP would use local paths.
Cron运行命令,因为它们将通过shell运行,因此运行PHP将使用本地路径。
You need to use a command like:
您需要使用如下命令:
php /home/USER/public_html/cron.php
Or if including the query string is necessary, use cURL instead (if it's installed):
或者,如果需要包含查询字符串,请改用cURL(如果已安装):
curl http://www.wetube.org/cron.php?id=01001
You might want to look at not exposing your cron scripts to the internet - move them to outside your web directory because if someone finds it they can constantly reload it to spam your cron scripts (i.e. sending lots of emails)
您可能希望不要将您的cron脚本暴露给互联网 - 将它们移到您的网络目录之外,因为如果有人发现它,他们可以不断地将其重新加载到您的cron脚本垃圾邮件(即发送大量电子邮件)
#2
7
I would add hash like
我会添加哈希像
curl http://www.wetube.org/cron.php?id=01001&hash=cm349ucKuc023b2ynGyv23ycr23
and in php file
并在PHP文件中
if(isset($_GET['hash']) && $_GET['hash']=='cm349ucKuc023b2ynGyv23ycr23'){
....
stuff to do
....
}
*you can even add specific time/date check when it should be run.
*you can check IP
*generate sha512 (I would recommend) hashes in both cron and php file with the same salt and maybe even time and then check if they are the same - it would be impossible for a hacker to recreate it - except if he somehow gets your original hash setup
*您甚至可以在应该运行时添加特定的时间/日期检查。 *你可以检查IP *生成sha512(我建议)使用相同的盐在cron和php文件中进行哈希,甚至是时间然后检查它们是否相同 - 黑客不可能重新创建它 - 除非是他以某种方式得到你原来的哈希设置