Code to generate alternative CSS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Code to generate alternative CSS

Post by mrvanjohnson »

Just looking for a little help with code clean up. Been hacking around with this and it works great but it looks too sloppy. I was wondering if there might be a better way of doing this. Here's the story, the people access the site have a high percentage of elderly. To make the site more accessible, I added a button that then loads an alternative CSS file with basically just larger fonts. Loads the preference in a session and follows them around while they are on the site. Like I said, I got it working but there must be a better way of doing it... Any suggestions? Here is how I got it working.

Code: Select all

<?php
	session_start();
	if ($_REQUEST['zoom'] == "off"){
		session_unregister('zoom');
		$css_image = "css_plus.gif";
		$css_image_var = "on";
		$css_image_alt = "View larger fonts for easier viewing";
		$css_sheet = "gsfcu_style.css";
	}elseif ($_SESSION['zoom'] == "on"){ 
		$css_image = "css_minus.gif";
		$css_image_var = "off";
		$css_image_alt = "View normal sized fonts";
		$css_sheet = "gsfcu_style2.css";
	}elseif ($_REQUEST['zoom'] == "on"){
		$zoom = "on";
		session_register('zoom');
		$css_image = "css_minus.gif";
		$css_image_var = "off";
		$css_image_alt = "View normal sized fonts";
		$css_sheet = "gsfcu_style2.css";
	}elseif (!($_SESSION['zoom'])){
		$css_image = "css_plus.gif";
		$css_image_var = "on";
		$css_image_alt = "View larger fonts for easier viewing";
		$css_sheet = "gsfcu_style.css";;
	}
	
?>
graphicmd
Forum Newbie
Posts: 8
Joined: Mon Jul 28, 2003 11:37 pm

Post by graphicmd »

I use two stylesheets on my website also. One to add the navigtion to the right side of the page, and one to add the navigation to the left. I actually use JavaScript to do this, but PHP would be much cleaner.

This might work for you.

Code: Select all

<?
if (isset($_COOKIE['style'])) {
	$style = $_COOKIE['style'];
} else {
	$style = "css_page1.css";
}
?>
<link rel="stylesheet" type="text/css" media="screen" href="<?= $style ?>" />
Post Reply