webmasters.icecaves.net -  - Blog -  -  -  -  - Forums
Hello, Guest! - Register -
ArticlesHTML & CSS ScriptsJavaScript ScriptsPHP ScriptsForums Index Mar 11,  PST
How to make a Skin/Theme changer with PHP
Written by: Thomas, Haily | Learn how to make a Skin/Theme changer with PHP.
  Mxx Digg StumbleUpon  

The first step is to make a new file and call it skins.php. This is the page you will be using to modify your skins. Copy and paste the code below to that file. You will need to modify this code to work with your skins.
Code:
<?php
$listofskins = array(

'Skin Name' => 'http://yoursite.com/skin1.css',
'Second Skin' => 'http://yoursite.com/skin2.css',
'Third Skin' => 'http://yoursite.com/skin3.css',

);
if(isset($_GET['changeskin']) && isset($listofskins[$_GET['changeskin']])){
setcookie('siteskin', $_GET['changeskin'], time()+31536000, '/');
header('Location: '.$_SERVER['HTTP_REFERER']);
die();
}
?>


Find this part of the code.
Code:
'Skin Name' => 'http://yoursite.com/skin1.css',
'Second Skin' => 'http://yoursite.com/skin2.css',
'Third Skin' => 'http://yoursite.com/skin3.css',


Give each skin a name then put the CSS file URL there. The first skin will be the default skin. If you are using any single quotes (') be sure to put a backslash (\) before it in order for this script to work properly.
Note: You are free to add more then three skins just be sure each skin has a different name.

Once that is complete get the path to the file skins.php. It should look something like this: /home/username/public_html/skins.php. Once you have the path to the file put it in the following code where it says DIRECTORY.

Code:
<?php
include('DIRECTORY');
?>


You will need to put that code at the top of every page that you want your skins to work on.


Put the following code anywhere between the tags.
Code:
<?php
echo'<link rel="stylesheet" type="text/css" media="screen" title="Site Skin" href="';
if(isset($_COOKIE['siteskin'])){
echo $listofskins[$_COOKIE['siteskin']];
}else{
reset($listofskins);
echo current($listofskins);}
echo'">';
?>


You don't need to modify anything in the above code.


The skin change form
The following code is the form that your visitors can use to change the skin.
Code:
<?php
echo'<form action="" method="get" name="skinchanger"><select name="changeskin" onChange="document.skinchanger.submit()">';
foreach($listofskins as $skinname => $skinurl){
echo'<option value="',$skinname,'"';
if($_COOKIE['siteskin'] == $skinname){
echo' selected';
}
echo'>',$skinname,'</option>';
}
echo'</select></form>';
?>


How to add/remove any skins
If you're getting tired of one of your skins you may remove it. First you need to open up the file you made called skins.php. Next, add/remove any skins then save your file. That's it! Thanks for reading. If you have any questions about this feel free to comment below or ask a question on our PHP forums.


  Mxx Digg StumbleUpon  

| Written by: Thomas, Haily | Added: Jan 22 2010 | Last Modified: Jan 22 2010 | Views: 586 | (Log in to rate) |

Member Comments

Puffs of ipawd.netJanuary 22 2010, 6:18 pm PST - Karma: 0 - Quote - Link -
5/5
YAY! Cool! I might use this one day.
Icy of icecaves.netJanuary 22 2010, 6:22 pm PST - Karma: 0 - Quote - Link -
4.5/5
Great article, guys
jules of rabidish.orgJanuary 22 2010, 6:43 pm PST - Karma: 0 - Quote - Link -
5/5
Excellent tutorial, guys! I actually never knew it was this simple.
ZaphiieJanuary 22 2010, 9:34 pm PST - Karma: 0 - Quote - Link -
5/5
Goshdang - I've always avoided skins 'cause I thought it was really hard D: How stupid of me.  
Jenny of windymill.skyness...January 23 2010, 7:45 am PST - Karma: 0 - Quote - Link -
4.5/5
Beautiful, I needed this as well because I always hate the theme of Windymill, so if I do, I'll just switch default. My site is more for me than anyone else.

In order to post a comment, you must be logged into the IceCaves.net Community.
Click here to login.


Figmint WindymillDaily Cute
The IceCaves.net Topsites


Rabidish | KeliJo.net | Spicy-Sugar | Neoeditor | Daily Neopets | RockyRoadRules | Smiley Helper | Figmint | Windymill | Dash of Color | Moo Lovett | Guildpets | Arid Seas | The New Fearless | Paint-Pops.net | Neo Crave