取消标题(刷新)

时间:2016-04-26 18:07:38

标签: php header http-redirect cancellation

调用它后是否可以取消它:

<?php
// Start output while creating profile
if (ob_get_level() == 0) ob_start();

for ($i = 0; $i<1; $i++)
{
    // Redirect user and download the profile
    header('Refresh: .02; download.php');
    echo "You're profile is being created, please wait...";

    ob_flush();
    flush();
    sleep(1);
}

ob_end_flush();

// Start creating the profile
// Start this after the code above due to the long execution time
if(!createProfile())
{
    // If createProfile returns false, cancel redirect and stop execution
    cancelRedirect();
    // Inform the user about the problem
    echo 'Error!';
    exit;
}
?>

意图是调用header() - 函数,然后脚本执行某些操作,如果结果不符合预期,则重定向到&#34; download.php&#34;应该被取消。

1 个答案:

答案 0 :(得分:0)

这是不可能的,但反过来是可能的:

<?php
    if (doSomething()) {
        header('Refresh: 1; download.php');
    }
?>