Jump to content


Photo

Session and XHTML validation error


  • Please log in to reply
3 replies to this topic

#1 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 30 June 2006 - 03:16 PM

I just made a style switcher for my site and now the page doesn't validate

The site is www.chrisgmyr.com go to the validation results.

here is style-switcher.php
<?php 
session_start(); 
$all_css = array(); 

$all_css['default']['file'] = "css/style.css"; // default 
$all_css['red']['file'] = "css/red.css"; 
$all_css['blue']['file'] = "css/blue.css"; 
$all_css['green']['file'] = "css/green.css"; 

$all_css['default']['label'] = "Default"; // default 
$all_css['red']['label'] = "Red"; 
$all_css['blue']['label'] = "Blue"; 
$all_css['green']['label'] = "Green"; 

$default_value = "default"; // set the default value here 

if (isset($_GET['change_css']) && $_GET['change_css'] != "") { 
    $_SESSION['css'] = $_GET['change_css']; 
} else { 
    $_SESSION['css'] = (!isset($_SESSION['css'])) ? $default_value : $_SESSION['css']; 
} 
switch ($_SESSION['css']) { 
    case "red": 
    $css_file = "css/red.css"; 
    break; 
    case "blue": 
    $css_file = "css/blue.css"; 
    break; 
	case "green": 
    $css_file = "css/green.css"; 
    break; 
    default: 
    $css_file = "css/style.css"; 
} 
function style_switcher() { 
    global $all_css,$PHP_SELF; 
	$self = $PHP_SELF; 
	$stripslash = explode("/", $self);
	$self = $stripslash[1];
	
    $style_links = ""; 
    foreach ($all_css as $key => $val) { 
        if ($_SESSION['css'] != $key) { 
            $style_links .= "<a href=\"$self?change_css=$key\">"; 
            $style_links .= "".$val['label']."</a>"; 
        } else { 
            $style_links .= "<span class=\"current\">".$val['label']."</span>"; 
        } 
    } 
    return $style_links; 
} 
?>

any ideas on what I can do to fix it?

Thanks,
-Chris

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 June 2006 - 03:18 PM

Easy solution - adjust the arg separator - http://www.w3.org/QA.../04/php-session
Legend has it that reading the manual never killed anyone.
My site

#3 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 30 June 2006 - 03:31 PM

cool, thanks i'll check it out

#4 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 01 July 2006 - 06:37 AM

I just decided to change it to cookie based instead...it works great!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users