Hi PHP masters!

I'm trying to write a PHP script that rotates an image based on what time of day it is. I want the script to show day.jpg from 6 AM to 6 PM, and to show night.jpg from 6 PM to 6 AM.

I also need the rotation to take place based not on server time, but on the local time of the user viewing the page.

I've Google-searched this for hours and only found stuff that is similar but doesn't do what I want. I don't want the rotation to be "every X minutes" and I don't want it to be based on the date, but rather on the exact time of day based on a user's local time.

Thank you SO much. This is very important to me.

Best,

Robert

    php does not know the visitors time its server side, i suggest you look for a JavaScript option.

      That's okay--is there a way to do it from the server time using PHP?

      I suck at coding 🙁

        date('G') will give you the hour in 24hour format, i assume you can figure out the rest.

          Okay, this is a bit embarrassing, but I can't code for ****. 🙁

          This is the only time I'll be needing PHP--I'm using basic HTML for everything else on my site.

            this is a forum for people who want to learn php, not a place to get free scripts written. However

            <?php
            $hour= date('G');
            if($hour > 5 && $hour < 19){
            	echo '<img src="day.jpg">';
            }else{
            	echo '<img src="night.jpg">';
            }
            
            ?>
            

              Wow, thanks man. That works!

              I'm sorry, I know this forum is for people who want to learn PHP. I was a little desperate because I have to meet a deadline on a project.

              Anyway, you totally saved my life! 🙂 Thank you again.

                Write a Reply...