March 22, 2012

How to synchronize all mobile devices accesing a web page?

Question by Jorge Ortega

It might use a cronjob in PHP. What I need is to display something at the same time, at a specific hour, in all devices that are accessing a determined url at that time (i.e. 12:00:00).

Answer by Starx

You might have to use SERVER TIME for this, since client time cannot be trusted. So, send a POST request to page, regularly to check for the time and get the output if the time is correct and then show.

Example:

JS:

setInterval(checkRegular, 60000);
function checkRegular() {
    $.post('check.php', function(data) {
         if(data.length) {
              //show the message
         }
    }
}

PHP:

<?php 
if($time==$requiredTime) {
   echo "the message";
}
?>

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!