[PHP]Cookies for layoutswitching.. HELP!
I've tried to use the GET method, but that didnt work.
Now, using cookies:
my get.php:
PHP Code:
<?php
if ($_COOKIE['style'] == '1') {
echo "<link href=\"styles/phaos.css\" type=\"text/css\" rel=\"stylesheet\" />";
} else if ($_COOKIE['style'] == '2') {
echo "<link href=\"styles/phaos2.css\" type=\"text/css\" rel=\"stylesheet\" />";
}
?>
And using GET for index.php:
PHP Code:
if ($_GET['style'] == '1' || $_GET['style'] == '') {
include "aup.php";
}
else if ($_GET['style'] == '2') {
include "aup2.php";
}
in aup.php:
PHP Code:
<?php
define('AUTH',true);
include "config.php";
include_once 'include_lang.php';
if ($_POST) {
setcookie('style','1');
}
if ( !$auth ) {
echo "<html> //etc etc
in aup2.php:
PHP Code:
<?php
define('AUTH',true);
include "config.php";
include_once 'include_lang.php';
if ($_POST) {
setcookie('style','2');
}
if ( !$auth ) {
echo "<html> //etc etc
Now, this'll work for index.php, but as soon as you login, it sets the cookie 'style' to '1' automatically.
Re: [PHP]Cookies for layoutswitching..
This is the style switching I use for my blog:
Put this in the header:
PHP Code:
<?php
if ($_COOKIE['style'] == 1 && $_GET['style'] != 2 || $_GET['style'] == 1 ) {
setcookie('style', 1,time() +60*60*24*30, '/');
echo "<link href='css/css.css' rel='stylesheet' type='text/css' />";
$style = 1;
} else if ($_COOKIE['style'] == 2 && $_GET['style'] != 1 || $_GET['style'] == 2) {
setcookie('style', 2,time() +60*60*24*30, '/');
echo "<link href='css/css2.css' rel='stylesheet' type='text/css' />";
$style = 2;
} else {
echo "<link href='css/css.css' rel='stylesheet' type='text/css' />";
$style = 1;
}
?>
Style switcher:
PHP Code:
<form name="jump">
<select name="menu" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">
<optgroup label="Style chooser"></optgroup>
<?php
if($style == 1) {
echo "
<option value='?style=1'>Pie-designs -- Light</option>
<option value='?style=2'>Pie-designs -- Darkorange</option>
";
} else if ($style == 2) {
echo "
<option value='?style=2'>Pie-designs -- Darkorange</option>
<option value='?style=1'>Pie-designs -- Light</option>
";
}
?>
</select>
</form>
If you use it, please give credits.
Re: [PHP]Cookies for layoutswitching..
EDIT : nvm, im testing it now!
For some reason it won't hop.. go to [url=http://phaos.fakezone.nl]World of Phaos -
Re: [PHP]Cookies for layoutswitching..
Because $style isn't set, which isn't really possible with my script unless you changed it...
Re: [PHP]Cookies for layoutswitching..
The only things i changed were the names.css, and i had to place '\' between all quotes, because the form gets echoed.