-3

I am sorry for the theoretical question. Just need to have some idea about loading the website content according to what time the user checks the website.

For example, it's a restaurant website and its morning time then it shows images of breakfast menu items. and if its evening time then it shows dinner images.

Just need a basic idea. can anyone help, please?

Scott Marcus
  • 57,085
  • 6
  • 34
  • 54
  • 2
    Who's time? The server's time or the client's time? What have you tried? Your question is far too broad. – j08691 Feb 21 '18 at 16:55

2 Answers2

2

You can get the current hour using date('H'), like this:

$time = intval(date('H'));

Once you have the time, you can show a different result to the user based on that:

if($time < 11) {
    echo "Good morning!";
} else if($time < 13) {
    echo "Lunch time!!";
} else if($time < 19) {
    echo "Good afternoon!";
} else {
    echo "Good night!";
}

Do not forget to set the correct timezone, using date_default_timezone_set('...');

Iter Ator
  • 5,817
  • 13
  • 53
  • 116
0

This needs to be accomplished with server-side code since visitors could be coming from various time zones or clocks that aren't in perfect sync with yours. Additionally, someone could adjust their system clock and then visit your page with the wrong time, thus seeing images that you didn't intend to be seen at that moment.

Languages like .php or ASP.NET or .jsp are what you need to use. They will execute code on the server, prior to the page being delivered to the client and that code will simply check the server-time and decide which image to include in the rendered page.

Scott Marcus
  • 57,085
  • 6
  • 34
  • 54
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/165589/discussion-on-answer-by-scott-marcus-loading-website-content-and-images-accordin). – Brad Larson Feb 21 '18 at 18:23