The way I would do this is using some ajax, and a server side language (php works).
You would use the ajax and javascript to hit your server and let the server tell the client what to draw. (having that logic server side would ensure that everyone would see the same thing).
Then to keep all the clients updated, I would put that ajax call on some time of timeout (via setTimeout
, that would basically re-ask the server every say 10 seconds if it should change what is shown.
the javascript would look something like this (using jquery here)
<script>
function getDataFromServer() {
var options = {
type: "GET", //make a GET http request
url: "/myServerSidePHPPage", // to the server at this location
dataType: "json" //make your php page return json
};
$.ajax(options).then(function (data) {
//data will be the json that your php page returns
//use this data to update your page
//pretending you have a <div id='weather'> somewhere on your page
//and also assuming you returned json with a weatherDescription property
//you could load the text or html into that div like::
$('#weather').html(data.weatherDescription);
});
}
//this is the jquery onDocumentReady function, it fires when the page loads
$(function() {
//tell the page to call the getDataFromServer function every
//10 * 1000 milliseconds (10 seconds)
window.setTimeout(getDataFromServer, 10 * 1000);
});
</script>
I dont' know php to help you with that part, but hopefully this can get you started and once you hit more specific problems you can ask questions about those.
As for outward appearing randomness you can do that in several ways. One easy way that comes to mind is to generate a random 'weather', and store it a text file with the time it was generated. Your php action could read this text file to give the clients the random weather, and also read the time it was generated to see if 24 hours has passed. If 24 hours pass generate a new random weather. (You could just store these values in memory on the server as well)