Вопрос

I would like some guidance in this. I am creating an update for a website that will allow a customer to subscribe to buy ebooks and have them sent out each month and automatically bill. I know how to use a sql database and PHP to keep track of members etc, but how do I make my website so that it will schedule things automatically at certain intervals. I tried Google searching, but maybe I didn't know how to phrase it.

Это было полезно?

Решение

With the help of Cron Job, on Linux hosts. Cron job can be used to automate your php script. So you write a script that does what you want and schedule it with Cron. Best approach is to write in the table when do you want Cron to run. For instance:

You have a column named "SendBook" with the date when the book should be sent. You set your php script to check if today is that date and if it is, send the book. For more help, visit this site

Code example:

$sevendays = date('Y-m-d', strtotime("+7 days")); // date is set to seven days from now
$sql= "INSERT INTO tablename (SendBook) VALUES ('$sevendays')"; // date is passed to the table
mysql_query($sql);

Than you create php script that checks if today is that date:

$checkdate = date("Y-m-d");
$sql = "SELECT SendBook AS '$comparedate' FROM tablename";
mysql_query($sql);
if ($checkdate == $comparedate){
// send email or whatever you want to do
}

Than simply make second script run whenever you want with Cron

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top