Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

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


No replies to this topic

#1 SzamanGN

    Newbie

  • Kontributors
  • Pip
  • 3 posts

Posted 03 January 2011 - 07:57 PM

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 timezone
date_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 timezone
date_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).




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users