hi everyone im new to PHP, i want to create a page by using PHP in such a way that page should contains a few color change options and themes by selecting those colors or themes it should refelect in the same page. can anyone pls help me by giving sugessins or proving a script for that..
One of the easiest ways to get some sort of personalized theme for a php site is to use different stylesheets for different themes and store them into the users' browser cookies. Not the most ideal but works for most users.
Say you have 3 stylesheets named default.css, theme1.css and theme2.css.
default.css:
body {
color: blue,
background-color: white;
font-family: arial;
}
theme1.css:
body {
color: black,
background-color: yellow;
font-family: verdana;
}
Here's a sample code to output the link to different stylesheet depending on what was stored in the cookies else use a default one.
<head>
<?php
if (!isset($_COOKIE['siteTheme']))
echo '<link rel="stylesheet" type="text/css" href="/css/' . $_COOKIE["siteTheme"] . '" />";
else
echo '<link rel="stylesheet" type="text/css" href="/css/default.css" />';
?>
<!-- other elements in head -->
</head>
To store the user selected theme, you might have a dropdown or hyperlinks to a page which will then set the cookies.
Say a hyperlink to "setTheme.php?theme=theme1", "theme=theme2" etc.
Or a dropdown form
<form method='get' action='/setTheme.php'>
<select name='theme' onchange='this.form.submit();'>
<option value='default'>default</option>
<option value='theme1'>Theme 1</option>
<option value='theme2'>Theme 2</option>
</select>
</form>
In the setTheme.php page, add the following:
<?php
$expire=time()+60*60*24*30; //exipiry of the cookie
setcookie("siteTheme", $_GET["theme"], $expire); //store the selected theme to cookie
?>
Then have a link back to the home page with the theme stylesheet selection code (the first one right above) in place, and you are done.
PS: Will not work for browsers not support cookies or cookie disabled.
Disclaimer: I've not tested the actual codes above, but conceptually it should work.