Jump to content

Stylesheet switcher


Natechs

Recommended Posts

I have three stylesheets, and I want the user to be able to change back and forth at will. But I don't know how to do that. Also, the logo changes too.Logo code:<div id="header"><!-- Header --><a href="/"><img src="logo.gif" alt="Nathan C:: Web Designer" /></a></div>I want to keep the hyper link and centering. I can live without the link but I really want the centering.Thanks,Nathan.

Link to comment
Share on other sites

You'll need some code to set the session var based on the user's selection, e.g. switch.php

<?php	session_start();	$_SESSION['style'] = $_GET['style'];	header("location:{$_SERVER['HTTP_REFERER']}");?>

Some links:

<a href="switch.php?style=style1">Style 1</a> <a href="switch.php?style=style2">Style 2</a>

And the style definition using the session var:

<link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['style']; ?>" />

Don't forget to put session_start() before output on all your pages!

Link to comment
Share on other sites

Is there a way to make it so that there is a default style so that my page is styled when someone first sees it and keeps the style changing feature?

Link to comment
Share on other sites

You can use a conditional to specify the stylesheet if the SESSION var isn't set

<link rel="stylesheet" type="text/css" href="<?php echo isset($_SESSION['style']) ? $_SESSION['style'] : "defaultstyle.css"; ?>" />

Link to comment
Share on other sites

Last question: Is there a way that when the user closes their browser then views my site again, the style still stays like when they closed it?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...