Like you already know there are cron jobs (server side) wich allow you to execute some php scripts at a precise time on your server/host.
If you want that your users see different pages at a certain hour of the day(or a specific time) by loading different content with ajax . Here is a very short example.
1.ajax function for modern browsers(chrome,safari,ie10,ios,android..)
2.time check
3.get night or day content.
function ajax(a,b,c){//url,function,just a placeholder
c=new XMLHttpRequest;
c.open('GET',a);
c.onload=b;
c.send()
}
var h=new Date().getHours();
// if it's after 12pm & before 6am it returns night else day.
nightday=(h>0&&h<6?'night':'day')+'.php';
//get the data from file 'day.php' or 'night.php'
ajax(nightday,function(){
//this.response is the content
console.log(this.response);
});
if you want to execute this just once:
window.onload=function(){
var c=new XMLHttpRequest,h=new Date().getHours();
c.open('GET',(h>0&&h<6?'night':'day')+'.php');
c.onload=function(){console.log(this.response)};
c.send()
}
And from here there are now various ways to check what time it is.
on every click,on some specific clicks,setTimeout(bad),setIntervall(bad)..and much more.
night.php
<?php
//load the content for night
?>
day.php
<?php
//load the content for day
?>
readfile
the appropriate file. You should decide on how long "midnight" is though; the traditional definition is that it's a point in time, closest JavaScript comes to it is milliseconds, and if you require users to hit the millisecond of midnight, not many will see your midnight page. – Amadan 13 hours agocurl
incrontab
is the right way to do it. – Amadan 13 hours ago