2013-12-19 64 views
1

我想在PHP中創建應用程序。自動重定向到定期插入的其他頁面

概念非常簡單,我想只是自動每隔一頁定期自動加載每一頁。 例如,如果我進入facebook.com,它會自動加載隨機profile.php,notifications.php,messages.php等...我不確定它的實用性。所以我的問題可能很愚蠢,但我需要幫助。我只知道元刷新只是爲了刷新頁面。

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

但我認爲,使用循環,我的概念將工作。但我不知道如何循環將使用元標記。

我希望你們能幫助我。

+0

你提的問題是非常廣泛的。你沒有顯示任何代碼,你的問題沒有意義。想想看,四個小時後,所提供的解決方案都沒有與手頭的問題有任何關係。這告訴我這個問題太廣泛了。 –

+0

@ Justin E-你認爲給我點讚的人是傻瓜嗎? –

+0

@OP請查看我的更新答案,然後按照我的要求刪除您的投票。 –

回答

0

我終於得到了soloution,

<script> 
    var interval = 5; // in seconds 
    var pages = [ 
    'http://website.com/link1.php', 
    'http://website.com/link2.php', 
    'http://website.com/link3.php' 
    ]; 
    var current_page_index = 0; 

    setInterval(function() { 
    loadintoIframe('myframe', pages[current_page_index]); 
    current_page_index = (current_page_index + 1) % pages.length; 
    }, interval * 1000); // second setInterval param is milliseconds 
</script> 
0

下面的代碼會將您重定向到相應的頁面。您可以檢查時間戳,並且如果它與初始頁面加載時間戳有很大不同,請執行頭部命令。在這種情況下,你真的會更好地使用meta。

Header('Location: http://www.google.com'); 

嘗試:

while(1=1){ 
    sleep(5); 

    //Use one of the following methods to refresh. 
    echo "<meta http-equiv=\"refresh\" content=\"5; url=/profile.php?pid=".$profile_id."\">"; 
    Header('Location: /profile.php?pid='.$profile_id); 
    echo "<script>javascript:window.href.replace('/profile.php?pid=".$profile_id."');"; 
} 

也回顧:Server Sent Events

+0

這不是我的意思。請再讀一遍我的問題。 –

+0

你應該讓你的問題更清楚。 –

+0

請告訴我你需要什麼解釋? –

1

尋找奇怪的規定,無論如何,你可以在你的頁面得到載荷遞歸的方式使用後

sleep(5) 

功能.. 您應該閱讀this ..

+0

謝謝,你的回答讓我有些道理。我正在努力...... –