ALA’s PHP Switcher revisited

Recently, the webzine A List Apart published an article by Chris Clark that demonstrated stylesheet switching using PHP.

The technique works all fine and dandy unless you’re using a more recent installation that (sensibly) doesn’t have register_globals set, whereupon nothing much happens at all.

Fortunately, a couple of easy modifications script using the predefined variables syntax now in use since PHP 4.1.0 will take care of this.

First up, the code in “STAGE ONE: Setting styles” for the switcher.php file should read:


<?php
setcookie("sitestyle", $_GET["set"], time() + 31536000, "/", "yourdomain.com", 0);
header("Location: $HTTP_REFERER");
?>

Secondly, the code in “STAGE TWO: Detecting styles” should be:


<link rel="stylesheet" type="text/css" media="screen" title="User
Defined Style"
href="<?php echo isset($_COOKIE['sitestyle']) ? $_COOKIE['sitestyle'] : 'defaultstyle' ?>.css" />

And that should be just about it.

This entry was posted in Scripting and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>