Forum Moderators: coopster
<snip>
Made an image so it's easier to read.
When I visit my page it seems to set the SESSION variable every time. Even when I visit the page without sending a querystring and the SESSION variable is already set.. What have I done wrong in my code?
//set SESSION colour variable.
If I've passed a "querystring" to change the colours then change SESSION colour.
//extract SESSION colour variable.
If SESSION variable exists then extract it otherwise choose to set SESSION variable to orange.
//setup PAGE colors.
Use SESSION variable to setup my page colours.
[edited by: jatar_k at 7:17 am (utc) on April 9, 2005]
<?php//set SESSION color variable.
if($_REQUEST['color']) {
$_SESSION['color'] = $_REQUEST['color'];
}//extract SESSION color variable.
$color = "or";
if(isset($_SESSION['color'])) $color = $_SESSION['color'];//setup PAGE colors.
if($color=="bl") $bgcolor = 'bgblue';
elseif($color=="gr") $bgcolor = 'bggreen';
elseif($color=="pi") $bgcolor = 'bgpink';
else {
$_SESSION['color'] = "or";
$color = "or";
$bgcolor = "bgorange";
}
$imagename = './leftofcube_'.$color.'.png';?>
Simple check to see if it works. Can be modified for any session. Write it in a new php page and call it from your original script. If you get a blank screen, then you have problems with your script. I keep a copy of this around just for this purpose.
<?PHP
session_start();
header("Cache-control: private");
$color = $_SESSION['color'];echo $color;
?>
If no errors, then it works fine. If blank, you know to look into your code.
Hope it helps,
IamStang
session_start()
However I don't see the idea, why do you want to use session to store the color. Wouldn't it be better to store it in the cookie, so the user won't have to chose over and over again different color schemes?
Best regards!
Michal Cibor