Jump to content
xisto Community
Sign in to follow this  
SzamanGN

Php+Css How To Set Up Different Colors Of You Web Page Depended On The Daytime.

Recommended Posts

I want to have different colors on my Web Page for daytime and nighttime.

 

How to do it?

 

I need two CSS files:

 

day.css - styles for the daytime.

/* Day. */body{color: black;background-color: yellow;}

night.css - styles for the nighttime.

/* Night. */body{color: white;background-color: black;}

and small PHP code, to recognize the current hour to check the time.

<?php//Step #1 - Set teh timezonedate_default_timezone_set ("America/Denver");//Step #2 - Get current hour (in 24 hours system).$currentHour=date('H',time());//Step #3 - Check the daytime.if ($currentHour > 21 AND $currentHour < 7)	{	//Night.	echo 'night';	}	else	{	//Day.	echo 'day';	}?>

Now, I integrate the PHP code with my HTML code in the index.php file.

<html> <head>  <link REL="Stylesheet" HREF="<?php//Step #1 - Set teh timezonedate_default_timezone_set ("America/Denver");//Step #2 - Get current hour (in 24 hours system).$currentHour=date('H',time());//Step #3 - Check the daytime.if ($currentHour > 21 AND $currentHour < 7)	{	//Night.	echo 'night';	}	else	{	//Day.	echo 'day';	}?>.css" TYPE="text/css"> </head> <body>  <h1>The colours of the text and background are depended of the time:<br>- night style from 10 PM to 06 AM;<br>- day style from 06 AM to 10 PM.  </h1> </body></html>

Finally visitors can enjoy my Web Page (they can be surprise when they visit my page).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.