Dan rants: My color scheme code

Cameron asked about my color scheme code, and I realized I'd never published it. A little bit is explained in my rationale for web design , but here's the full details:

First, the Perl script:

#!/usr/bin/perl -w
use strict;
use CGI;
my ($query, $cookie);
$query = new CGI;
$cookie = $query->cookie(-name=>'colorscheme',
			 -value=>$query->param('scheme'),
			 -path=>'/',
			 -domain=>'.flutterby.com',
			 -expires=>'+10y');
print $query->redirect(-uri=>$ENV{'HTTP_REFERER'},
		       -cookie=>$cookie);
print "Redirect to <A HREF=\"$ENV{'HTTP_REFERER'}\">$ENV{'HTTP_REFERER'}</A> failed\n";

I then use Apache's server parsed HTML to choose the colors, my stock top of all documents "<BODY>" and first few lines looks like:

<!--#if expr="$HTTP_COOKIE=/colorscheme\=wb/" -->
<BODY TEXT=#AAFFFF BGCOLOR=#000000 LINK=#AA00FF ALINK=#8800AA>
Change color scheme
<A HREF="/cgi/color.cgi?scheme=bw">Black on White</A> /
<A HREF="/cgi/color.cgi?scheme=">Default</A>
<!--#elif expr="$HTTP_COOKIE=/colorscheme\=bw/" -->
<BODY TEXT=#000000 BGCOLOR=#ffffff LINK=#330088 ALINK=#000088>
Change color scheme
<A HREF="/cgi/color.cgi?scheme=wb">White on Black</A> /
<A HREF="/cgi/color.cgi?scheme=">Default</A>
<!--#else -->
<BODY>
Change color scheme:
<A HREF="/cgi/color.cgi?scheme=wb">White on Black</A> /
<A HREF="/cgi/color.cgi?scheme=bw">Black on White</A> /
<!--#endif -->

Depending on how your server is set up, if you don't want to change everything to .shtml, often you can make a ".htaccess" file which includes the line "XBitHack on" and set the execute bit on your HTML files.


Wednesday, September 15th, 1999 danlyke@flutterby.com