2016-04-26 15 views
0

それを呼び出した後、これをキャンセルすることが可能です:(リフレッシュ)ヘッダをキャンセル

<?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() -functionが呼び出されるということである、スクリプトが何かをして、期待通りの結果ではない場合「download.php」へのリダイレクトをキャンセルする必要があります。

+1

論理的には、それは意味がありません。 – Marcus

+0

それは 'header()'関数を呼び出す前に 'echo'が動作しないため、これを行う唯一の方法です。 – alve89

+0

しかし、 'header_remove()'はあります。 – mario

答えて

0

これは可能ではないですが、逆は可能です:

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

もちろんこれも可能ですが、残念ながらこれは私を助けません。それはJavaScriptで可能でしたか? – alve89

+0

JavaScriptでPHPコードを変更することはできません。 –

+0

ここにX-Y問題があるように見えます...完全な問題を教えてください。 @ alve89 ... –