2011-11-29 68 views
0

我有一個關於在PHP中定時重定向的問題 - 特別是在wordpress中。在Wordpress中使用PHP頁腳進行重定向

我們使用免費的Woothemes佔位符主題設置了一個網站,它非常有限。但這沒關係 - 該網站很簡單。

20秒後,我想頁面重定向到另一個URL - 是否可以插入一些代碼到footer.php來做到這一點?我發現什麼樣子權代碼:用延遲

//重定向: header('Refresh: 20; url=http://www.example.org/');

可這footer.php插入antwhere?

歡迎任何輸入。

+0

你試過了嗎?沒有理由不這樣做。 – switz

回答

2

您可以編寫只需在header.php中

<META HTTP-EQUIV="Refresh" CONTENT="20;URL=http://www.google.com"> 
0

是的,這可以在頁腳中使用。但請確保在標題中設置了ob_start()。否則,你會得到一個錯誤。

0

是的,它可以插入,但如果服務器已經有一些HTML,您將收到一個警告,如header already sent by .....,重定向將不會像它應該那樣工作。

相反,您可以通過使用要打印的ob_clear()清除輸出緩衝區中的所有內容來執行此操作,然後發送重定向標頭。

例子:

if($casespecial==true) { 
    ob_clean(); //make sure nothing is outputed to the browser 
    header('Refresh: 20; url=http://www.example.org/'); //now send the header param 

    //After wards, you can resume your normal code and output the template as you require 
    . 
    . 
    . 
}