自动定期自动重定向到其他页面

时间:2013-12-19 11:45:23

标签: php redirect autoload

我想用PHP创建一个应用程序。

概念很简单,我想只是定期自动加载每一页。 例如,如果我进入facebook.com,它会随机自动加载profile.php,notifications.php,messages.php等......我不确定它的实用性。所以我的问题可能是愚蠢的,但我需要帮助。我只知道元刷新,这只是为了刷新页面。

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

但我认为,使用循环,我的概念将起作用。但我不知道循环如何使用元标记。

我希望你们能帮助我。

3 个答案:

答案 0 :(得分:1)

看起来奇怪的要求,无论如何,你可以使用

sleep(5)
页面以递归方式加载后的

函数.. 你应该阅读this ..

答案 1 :(得分: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

答案 2 :(得分:0)

我终于得到了解决方案,

<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>
相关问题