2015-03-13 109 views
0

有沒有辦法在不使用header()的情況下重定向到php中的另一個頁面?我不能使用header(),因爲我先輸出一些東西到頁面。我已經考慮使用JavaScript的window.location,但我在php中使用if語句,所以有沒有辦法在PHP中去使用header()的另一個頁面?提前致謝。有沒有辦法在不使用header()的情況下重定向到php中的另一個頁面?

+0

喜歡這個? http://stackoverflow.com/questions/14955526/php-delay-on-redirect – 2015-03-13 13:35:29

回答

2

我不能用頭(),因爲我是第一個輸出一些東西到頁面。

您不應該使用header()解僱。使用output buffering仍然可以使用header()

例如:

<?php 

ob_start(); //start the buffer 
echo "This is some output"; //Output data 
ob_clean(); //Erase the buffer content 
header('Location: http://google.com'); //Redirect user 
0

使用PHP?編號

你已經提到過使用JS和window.location。

唯一的其他選擇是Meta refresh

<meta http-equiv="refresh" content="0; url=http://example.com/">

+0

你的意思就像我的評論? – 2015-03-13 13:38:40

+0

@JelledeFries不,不是。 – rjdown 2015-03-13 13:43:31

+0

是的,我很抱歉,我只閱讀了這個問題的評論。但我們的意思是一樣的,我只是沒有說出來,我很抱歉。 – 2015-03-13 13:49:34

相關問題