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";
}
?>