Reputation: 105
I want to refresh an HTML page every hour automatically in the background. I was thinking about using PHP but I'm not sure what if that's possible.
This is all the I have:
<meta http-equiv="refresh" content="3600" >
But this doesn't refresh automatically in the background. How can I do this? If this is possible in PHP and a cron job please let me know (with code preferably). Thank you.
Upvotes: 1
Views: 20692
Reputation: 902
Refer to this answer https://stackoverflow.com/a/19807718/6390490
Refresh document every 300 seconds using HTML Meta tag
EDIT: for background you have to use ajax something like this https://stackoverflow.com/a/25446696/6390490
function loadlink(){
$('#links').load('test.php',function () {
$(this).unwrap();
});
}
loadlink(); // This will run on page load
setInterval(function(){
loadlink() // this will run after every 5 seconds
}, 5000);
for server side refreshing use
header("Refresh: 300;url='http://thepage.com/example'");//set time here as per your need
Upvotes: 0
Reputation: 8101
You can use javascript setInterval();
<script>
$(document).ready(function(){
setInterval(function(){ reload_page(); },60*60000);
});
function reload_page()
{
window.location.reload(true);
}
</script>
Upvotes: 5
Reputation: 11830
Try this :
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "3600";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
Upvotes: 1