1

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.

0rkan
  • 845
  • 2
  • 18
  • 34
Ron
  • 105
  • 2
  • 2
  • 10
  • 1
    _"automatically in the background"_ ? What do you mean by that ? – Rayon May 27 '16 at 11:09
  • @Rayon automatically as in completely automatically. I just want to have to set it up and everyday it should refresh the HTML page every hour. – Ron May 27 '16 at 11:12
  • So basically your html page is cached somewhere and you want to set a new page every hour ? – abhinsit May 27 '16 at 11:12
  • You tagged the question with cron; So perhaps use it –  May 27 '16 at 11:35

3 Answers3

5

You can use javascript setInterval();

<script>
 $(document).ready(function(){
    setInterval(function(){ reload_page(); },60*60000);
 });

 function reload_page()
 {
    window.location.reload(true);
 }
</script>
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27
1

Try this :

<?php
    $page = $_SERVER['PHP_SELF'];
     $sec = "3600";
?>
<html>
    <head>
    <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
0

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
Community
  • 1
  • 1
smarttechy
  • 852
  • 1
  • 9
  • 23
  • but doesn't the website have to open for this to work? – Ron May 27 '16 at 11:36
  • for server side auto refreshing you can use header("Refresh: 300;url='http://thepage.com/example'"); – smarttechy May 27 '16 at 11:40
  • alright, so if I use that (the server side PHP) and try to run it as a cron job will it work? – Ron May 29 '16 at 14:11
  • its working for me why don't u try and test it and can tell your experience in comments – smarttechy May 30 '16 at 04:20
  • I used tried using the server side script (I only used that) and ran it as a cron job (in Godaddy). It didn't work. Do I have to use both the server side and client side code together? Thanks for your help. @smarttechy – Ron May 30 '16 at 11:46
  • Hi, I am using Server Side Scripting for my callback notification sections header("Refresh:10;url='https://domain/admin/callback.php'"); but the all the pages are redirecting to same page which I have given in URL section. Please help me out. Thank you. – Akash M Mar 03 '18 at 11:36