Auto redirecting to another pages at regular intervels

孤街浪徒 提交于 2019-12-08 06:45:57

问题


I want to create an application in PHP.

concept is very simple, I want to just auto load every page randomly at a regular intervals. For example, if i entered to facebook.com , it would be auto load randomly profile.php, notifications.php, messages.php etc... I am not sure about its practicality. So my question may be stupid, but i need help.I only know meta refresh which is only for refreshing the page.

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

But i think, using the loop , My concept will work. But i have no idea how loop will work with meta tag.

I hope you guys will help me.


回答1:


Looking strange requirement, anyhow, you can use

sleep(5)

function after your page get loads in a recursive way.. you should read this..




回答2:


The below code will redirect you to the appropriate page. You could check the time stamp, and if it is so much different than the initial page load timestamp, execute the header commmand. You really would be better off using meta in this case.

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."');";
}

also review: Server Sent Events




回答3:


I finally got the 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>


来源:https://stackoverflow.com/questions/20680916/auto-redirecting-to-another-pages-at-regular-intervels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!