PHP Eshop Closing Time Code Message

I was recently asked to code a little widget for someone’s Eshop to display a message at a certain time of day to say if they were open or closed.

The shop’s opening hours were 8:00am – 11:30am then 4:00pm – 10:00pm.

  1. <?php
  2.  
  3. $open_AM = mktime(8,0,0); //Open 8:00AM
  4. $close_AM = mktime(11,30,0); // Closing 11:30AM
  5. $open_PM = mktime(16,0,0); // Open 4:00PM
  6. $close_PM = mktime(22,0,0); // Close 10:00PM
  7. $offset = 7200;
  8.  
  9. //Current Server Time
  10. echo "Current server time: ";
  11. $t=time();
  12. echo(date("D F d Y H:i:s",$t));
  13. if ($t >= $open_AM &amp;&amp; $t <= $close_AM)
  14. {
  15. echo "Shop Open";
  16. }
  17. else if($t >= $open_PM &amp;&amp; $t <= $close_PM)
  18. {
  19. echo "Shop Open";
  20. }else{
  21. echo "Shop Closed";
  22. }
  23.  
  24. //Plus 2 Hours
  25. $t=time() + $offset;
  26. echo "Plus 2 hours: ";
  27. echo(date("D F d Y H:i:s",$t));
  28. ?>

I will now break this code down for you.