2013-08-07 81 views
0

當點擊提交按鈕它,我已經wriiten作爲問題與頭,同時它重定向到當前頁面

<?php 
    if (isset($_POST['delete'])): 
    $size = count($_POST['checkbox']); 
    for ($i=0; $i<=$size-1; $i++) { 
    $id = $_POST['checkbox'][$i]; 
    $wpdb->query("DELETE FROM wp_submitted_form WHERE id =".$id); 
    } 
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 
    endif; 
?> 

拋出的錯誤消息:

Cannot modify header information - headers already sent by (output started at /home/wizcorea/public_html/wp-admin/includes/template.php:1657) in /home/wizcorea/public_html/wp-content/plugins/submitted-form/view.php on line 54

我想要的頁面應該得到點擊提交按鈕後刷新

+1

如果你剛剛度過1分鐘搜索 「頭文件已經發出PHP」 你會發現成千上萬的結果,並有非常好的答案。看到這裏:http://stackoverflow.com/search?q=headers+already+sent+php – x4rf41

回答

0

使用PHP的ob_flush函數。在代碼的頂部添加這個函數。

<?php 

ob_flush(); 

而且這會起作用。

編輯:

,而不是驗證碼:

header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 

使用此代碼:

echo '<script>location.href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'"</script>'; 
+0

它仍然無法正常工作 – Nida

+0

@奈達我已經更新了答案檢查。 –

+0

它現在有效,但點擊提交後頁面會刷新兩次 – Nida