How to change background color of Body of a web page or any div or any section’s background color dynamically through PHP ?

Below is the example of changing background color of whole body dynamically of a webpage. You can further apply the same method for each and every div or for each and every section of your web page.


<!DOCTYPE html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title></title>
 <?php
 if(isset($_REQUEST['submit']))
 {
 if(empty($_REQUEST['bg']))
 {
 echo "Please write color name or color code";
 }
 else
 {?>
 <style> body{background-color:<?php echo $_REQUEST['bg'];?>;} </style>
 <?php }
 }
?>
</head>
 <body>
 <form action="index.php" method="post">
 <input type="text" name="bg"/>
 <input type="submit" name="submit" value="Change"/>
 </form>
 </body>
 </html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s