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

问题描述 投票:1回答:3

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

概念非常简单,我想按固定的时间间隔随机自动加载每个页面。例如,如果我输入到facebook.com,它将是自动随机加载profile.php,notifications.php,messages.php等...我不确定它的实用性。所以我的问题可能很愚蠢,但我需要帮助。我只知道仅用于刷新页面的元刷新。

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

但是我认为,使用循环,我的概念会起作用。但是我不知道循环如何与元标记一起工作。

php redirect autoload
3个回答
1
投票

看起来很奇怪的要求,可以使用

sleep(5)

您的页面以递归方式加载后的功能。您应该阅读this ..


0
投票

下面的代码会将您重定向到相应的页面。您可以检查时间戳记,如果它与初始页面加载时间戳记有很大不同,请执行标头命令。在这种情况下,使用meta确实会更好。

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

TrY:

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
投票

我终于得到了解决方案,

<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>
© www.soinside.com 2019 - 2024. All rights reserved.