Layout help
#1
Posted 06 July 2005 - 02:30 AM
#2
Posted 06 July 2005 - 03:04 AM
<?php
//session has to be started before html output
session_start();
echo"<html>\n";
echo"<head>\n";
if(isset($_GET['style']))
{
//put the new style selected by the user into the session
$_SESSION['style'] = $_GET['style'];
}
elseif(!isset($_GET['style']) && !isset($_SESSION['style']))
{
//if no style has been selected, set a default
$_SESSION['style'] = 1;
}
if(isset($_SESSION['style']))
{
//pick the current style and include that stylesheet
switch ($_SESSION['style']) {
case "1": $inc = 'stylesheet1.css';
break;
case "2": $inc = 'stylesheet2.css';
break;
case "3": $inc = 'stylesheet3.css';
break;
default: $inc = 'stylesheet1.css';
break;
}
}
$css_file = "<link href=\"".$inc."\" rel=\"stylesheet\" type=\"text/css\">\n";
echo $css_file;
?>
</head>
<body>
<a href="index.php?style=1">Style 1</a><br>
<a href="index.php?style=2">Style 2</a><br>
<a href="index.php?style=3">Style 3</a><br>
</body>
</html>
Basically, that code let's you choose between 3 stylesheets (you can edit it, of course), and remembers what you chose for as long as you don't close the browser window (a session).
Edited by greg, 06 July 2005 - 03:05 AM.
#3
Posted 06 July 2005 - 06:20 PM
Edited by Bengo, 06 July 2005 - 06:29 PM.
#4
Posted 06 July 2005 - 10:06 PM
#5
Posted 06 July 2005 - 11:54 PM
#6
Posted 07 July 2005 - 01:28 AM
#7
Posted 08 July 2005 - 11:05 AM
Here, I made one because I wanted to haev multiple skins my site at one point.
You might be too lazy to look at the link so i will post it here...
----------------------------------------------
As you may of seen on http://www.spoono.com They have a skin changer! This is something similar and it has the same idea as theirs. Just that this has a refresh page that will bring you back to the last page page you were viewing instead of going back to the home page.
1) First off, create your index.php This will have a very few lines of code, and add this in there:
Quote
ini_set("session.cookie_lifetime", "315360000");
session_start();
//Settign the styles
switch($_SESSION["style"])
{
case "red":
include("red.php");
break;
/*
To add a new skin, simply add:
case "NAME OF SKIN":
include("FILENAME TO SKIN");
break;
*/
default:
include("default.php");
break;
}
?>
All your skins will be in different files. Your default skin will be set to default.php So you would set up that file the same you would with index.php. If you wanted a red skin. You could simply create the red skin on the file red.php with the images set to the red images and etc. Please also note:
Quote
To add a new skin, simply add:
case "NAME OF SKIN":
include("FILENAME TO SKIN");
break;
*/
2) Now, create a style.php and insert this code:
Quote
ini_set("session.cookie_lifetime", "315360000");
session_start();
$_SESSION["style"] = $_GET["set"];
?>
Please Wait...
layout scheme selected, please wait to be redirected...
( Click here if you are not redirected in 3 seconds )
Please notice the code $HTTP_REFERER which is the last page you visited. If you did not visit a page before the style page is loaded. You are stuck
To change a skin, you can simply set a hyperlink to
Quote
Final Notes: Cookies must be enabled for this to work. Also, this is a lifetime cookie so it will take a LONG time to expire.
If you have any questions, comments, suggestions, please feel free to speak your mind.
Tutorial Copyright © 2005 Chaos King -- Pixel-Designz
#8
Posted 08 July 2005 - 11:11 AM
also, including all style sheets in the code and marking them as alternative stylesheets help the switching, as the user already has the stylesheet and the switch is seemless, almost instant
#9
Posted 08 July 2005 - 11:17 AM
Unfortunatly, I have not even tried to learn those...
Please say how would you do it in Java/AJAX, I can always learn something new!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
