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