Update page every minute

Hi Experts,

I have a page called online.php which contains some code I want to run every minute, when the user is online. I have attached the code from online.php.

How can I via AJAX/ or Query make this page reload every minute?

Thanks in advance!
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/session_start.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/generel.php");

// Check if the user is online
if (isset($_SESSION['MM_UserId'])) {
$sql="UPDATE users SET online_status=NOW() WHERE id = '".$_SESSION['MM_UserId']."'";

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Put this in head section :
<script language="javascript" type="text/javascript">
setTimeout(function() {
   var xmlhttp;
   if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   xmlhttp.onreadystatechange = function() {}
   xmlhttp.open("GET","yourpage.php", true);
}, 60000); // 60 x 1000ms = 1min

Open in new window

change yourpage.php with your page filename.
An old trick to refresh pages on a timer is to use META tags. What I think you're trying to do, however, is to monitor a user in the background to see if they're still online or not.

I would suggest setting up an Iframe on your page. This could be hidden (so as to genuinely be in the background), or could be included with advertising or some other object.

Create a page that shows the aforementioned advertising if desired, or that simply calls the PHP code if you prefer an invisible arrangement. In the HTML output on that page, place this in the <head> section:

<meta http-equiv="refresh" content="[..x..]" url="[..y..]" />

You will want to replace [..x..] with the number of seconds between refreshes (in your case, 60), and [..y..] with the URL of that page.

The effect will be that the web page inside the Iframe (and the PHP that is called upon each request) is executed every 60 seconds, without disturbing the rest of what your user is looking at.

If you are not familiar with Iframes and need help with this, I am happy to assist.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Looking at your solution, I see references to ActiveX. I have not done much work with ActiveX in the last few years, but from what I remember it works great in Internet Explorer but not at all in any other browser. Is that still the case?
>I see references to ActiveX.

Yes only if XMLhttpRequest is not available.
Check this page if you want more info : http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.