Background Changer!

By log2 on Dec 20, 2004

This is the best little snippet you'll ever see on this site, maybe. . . depends on how many years this site will be around, it's going pretty good right now, but anyway this snippet will make it so when you select the colour(color if you're American which I'm not) out of a drop down menu, it will change all the tables, and if you know how to make a web site then you know all you use are tables so it will pretty much change the background, well here it is F.Y.I. I'm kinda reluctant to give this away, this is ingenious, and even if the person leaves the site and comes back later, it will stay the same!
P.S. It's long, kinda like this description :)
P.S.S. I know there is a bit of unecessary stuff there but it's worth it ;)

<? @session_start(); 
$_SESSION['color']=$_POST['col']; 
$_SESSION['sel']=$_POST['inp']; 
$_SESSION['inp']=$_POST['inp'];
$_SESSION['text']=$_POST['tex']; 
?>
<? @session_start(1); 
$_SESSION['color']=$_POST['col']; 
$_SESSION['sel']=$_POST['inp']; 
$_SESSION['inp']=$_POST['inp']; 
$_SESSION['text']=$_POST['tex']; 
?>

<style type="text/css"> 
<!-- 
table { 
    background-color: <? if($_SESSION['color']!='') echo $_SESSION['color']; else echo '#999900'; ?> 
} 
td { 
    font-family: Verdana, Arial, Helvetica, sans-serif; 
    font-size: 12px; 
    font-weight: bolder; 
    color: #CCFF66; 
} 
font {

}
input { 
    background-color:<? if($_SESSION['inp']!='') echo $_SESSION['inp']; else echo '#663399'; ?> 
    font-family: Verdana, Arial, Helvetica, sans-serif; 
    font-size: 12px; 
    color: #FF0000; 
} 
select { 
    font-family: Verdana, Arial, Helvetica, sans-serif; 
    font-size: 12px; 
    color: #FFFFFF; 
    background-color:<? if($_SESSION['sel']!='') echo $_SESSION['sel']; else echo '#669999'; ?> 
} 
--> 
</style> 

<?
echo 'Banner color: ',$_POST['col']; 

?>
<br>
<form name="form1"  method="post" > 

      <?php    

function makeSelectMenu($menuName, $options, $chosen) { 
    $list = ''; 
    foreach ($options as $option => $text) { 
        $selected = ($chosen === $option) ? ' selected="selected"' : ''; 
        $list .= " <option value=\"$option\"$selected>$text</option>\n"; 
    } 
    return "\n<select name=\"$menuName\" id=\"$menuName\">\n$list</select>\n"; 
} 

session_start(); 

$options = array( 
'#336600' => '#336600 Dark Green', 
'#999966' => '#999966 Light Brown' ,
'#669966' => '#669966 Light Green' ,
'#ef5966' => '#ef5966 Pink',
'#3366ff' => '#3366ff Blue',
'#ff6600' => '#ff6600 Orange' ,
'#339900' => '#339900 Green' ,
'#335566' => '#335566 Navy' ,
'#66f9ff' => '#66f9ff Aqua' ,
'#efdf66' => '#efdf66 Mustard' ,
'#fd66ff' => '#fd66ff Fuscia' ,
'#ff66cc' => '#ff66cc Rose'
  ); 
  $menuName = 'col';
  if (isSet($_POST[$menuName])) { 
    $_SESSION[$menuName] = $_POST[$menuName]; 
} 

if (isSet($_SESSION[$menuName])) { 
    $chosen = $_SESSION[$menuName]; 
} else { 
    $chosen = ''; 
} 

$selectMenu = makeSelectMenu($menuName, $options, $chosen);  

?>

<?
$options = array( 
'' => 'Choose the Background',
'#336600' => '#336600 Dark Green', 
'#999966' => '#999966 Light Brown' ,
'#669966' => '#669966 Light Green' ,
'#ef5966' => '#ef5966 Pink',
'#3366ff' => '#3366ff Blue',
'#ff6600' => '#ff6600 Orange' ,
'#339900' => '#339900 Green' ,
'#335566' => '#335566 Navy' ,
'#66f9ff' => '#66f9ff Aqua' ,
'#efdf66' => '#efdf66 Mustard' ,
'#fd66ff' => '#fd66ff Fuscia' ,
'#ff66cc' => '#ff66cc Rose'
  ); 
    $menuName = 'col'; 
$chosen = ''; 
if (isSet($_POST[$menuName])) $_SESSION[$menuName] = $_POST[$menuName]; 
if (isSet($_SESSION[$menuName])) $chosen = $_SESSION[$menuName]; 
$selectMenu = makeSelectMenu($menuName, $options, $chosen); 

?> 

<form method="post"> 

<?php echo $selectMenu; ?> 

    <?php    

function makeSelectMenu1($menuName1, $options1, $chosen1) { 
    $list1 = ''; 
    foreach ($options1 as $option1 => $text1) { 
        $selected1 = ($chosen1 === $option1) ? ' selected="selected"' : ''; 
        $list1 .= " <option value=\"$option1\"$selected1>$text1</option>\n"; 
    } 
    return "\n<select name=\"$menuName1\" id=\"$menuName1\">\n$list1</select>\n"; 
} 

session_start(1); 

    $options1 = array( 
'' => 'Choose the Background',
'#336600' => '#336600 Dark Green', 
'#999966' => '#999966 Light Brown' ,
'#669966' => '#669966 Light Green' ,
'#ef5966' => '#ef5966 Pink',
'#3366ff' => '#3366ff Blue',
'#ff6600' => '#ff6600 Orange' ,
'#339900' => '#339900 Green' ,
'#335566' => '#335566 Navy' ,
'#66f9ff' => '#66f9ff Aqua' ,
'#efdf66' => '#efdf66 Mustard' ,
'#fd66ff' => '#fd66ff Fuscia' ,
'#ff66cc' => '#ff66cc Rose'
  ); 
    $menuName1 = 'inp'; 

if (isSet($_POST[$menuName1])) { 
    $_SESSION[$menuName1] = $_POST[$menuName1]; 
} 

if (isSet($_SESSION[$menuName1])) { 
    $chosen1 = $_SESSION[$menuName1]; 
} else { 
    $chosen1 = ''; 
} 

$selectMenu1 = makeSelectMenu1($menuName1, $options1, $chosen1);  

    $options1 = array( 
'#336600' => '#336600 Dark Green', 
'#999966' => '#999966 Light Brown' ,
'#669966' => '#669966 Light Green' ,
'#ef5966' => '#ef5966 Pink',
'#3366ff' => '#3366ff Blue',
'#ff6600' => '#ff6600 Orange' ,
'#339900' => '#339900 Green' ,
'#335566' => '#335566 Navy' ,
'#66f9ff' => '#66f9ff Aqua' ,
'#efdf66' => '#efdf66 Mustard' ,
'#fd66ff' => '#fd66ff Fuscia' ,
'#ff66cc' => '#ff66cc Rose'
  );

    $menuName1 = 'inp'; 
$chosen1 = ''; 
if (isSet($_POST[$menuName1])) $_SESSION[$menuName1] = $_POST[$menuName1]; 
if (isSet($_SESSION[$menuName1])) $chosen1 = $_SESSION[$menuName1]; 
$selectMenu1 = makeSelectMenu1($menuName1, $options1, $chosen1); 

?> 

<form method="post"> 

<?php echo $selectMenu1; ?> 

      <input type="submit" name="Submit" value="Submit">

</form> 

Comments

Sign in to comment.
DeathRyder082   -  Jul 16, 2005

so you save it like code.php and then copy it to an html code? sorry im just trying to figure this out

 Respond  
log2   -  Jan 22, 2005

anywhere in an html code, but you must save the file as *.php and the host must support php 4.02 or over 4.0

 Respond  
PoiXon   -  Jan 19, 2005

where do we paste PHP snippets?

 Respond  
Shadow_Slayerz   -  Jan 07, 2005

Whooh, Nice Php!!, we need more php scripters

 Respond  
Shadow_Slayerz   -  Jan 07, 2005

Whooh, Nice Php!!, we need more php scripters

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.