当contor达到特定值时,自动移至下一页

时间:2014-10-11 11:01:47

标签: php

我正在尝试构建一个脚本,用于向用户发送电子邮件,并在x个电子邮件发送后1小时暂停。但是我得到了' Page没有正确地重定向'尽管我手动访问查询字符串它的工作原理:

cron-wordpress.php?page=1 // works manually
cron-wordpress.php?page=2 // works manually
cron-wordpress.php?page=3 // works manually

以下是剧本的内容:

编辑简化了问题

时钟守护wordpress.php

$page = isset($_GET['page']) ? $_GET['page'] : 0;
$divide = 10;
$start = $divide*$page;
$emails = array();
for ($i = 0; $i <= 300; $i++) { // 300 emails in the dbs that means 30 pages $divide = 10
    array_push($emails, $i.'@email.com');
}
$emails = array_slice($emails, $start, $divide);
$url = "http://".$_SERVER['SERVER_NAME'].'/wordpress/blog/cron_test.php';

$count = 0;
foreach ($emails as $email) {
    echo 'Mail send to '.$email.'<br>';
    $count++;
    if (($count % $divide == 0) !== false && $count < 2000) {
        sleep(2);
        $page_nr = $count/$divide + 1;
        header('Location: '.$url.'?page='.$page_nr);
        //die();
        //exit;
    }
}

0 个答案:

没有答案