Change Background Color of Page Every Day in PHP

by Hiroshi on January 17, 2013

in Date & Time

You can change webpage background page everyday. Its a simple PHP code tha takes day value and uses a little CSS style to do that. Here it is.

Add this code in head section of page.

<style type="text/css">
<!--
.bodybg {
	<?php $dayforbackground=date('N'); ?>
	<?php if ($dayforbackground==1) { ?>background-color: #f7f8f2;<?php } ?>
	<?php if ($dayforbackground==2) { ?>background-color: #f5f9EC;<?php } ?>
	<?php if ($dayforbackground==3) { ?>background-color: #C4E4ED;<?php } ?>
	<?php if ($dayforbackground==4) { ?>background-color: #f7f8f2;<?php } ?>
	<?php if ($dayforbackground==5) { ?>background-color: #f5f9EC;<?php } ?>
	<?php if ($dayforbackground==6) { ?>background-color: #C4E4ED;<?php } ?>
	<?php if ($dayforbackground==7) { ?>background-color: #f7f8f2;<?php } ?>
}
-->
</style>

Call this style class in body tag.

class="bodybg"

like below

<body class="bodybg">

That’s it.

Related Posts

Previous post:

Next post: