[ back to toc ]

Message Board Color: Where is the code?

Date: 2001/12/30 11:45

Q:
I have a message board script I acquired from a friend who got it from a
book. I got the script working alright but I can't stand black and white.

I have included the code below for you to look at it... to tell the truth
I don't know exactly what I'm supposed to look for. I was looking for
some hexadecimal values but couldn't find any. The text comes out black
and the background white. I've got the colors I'd like to use... I just
don't know how to implement them. Any suggestions/help/advice would be
much appreciated.

#!/usr/bin/perl -w

use 5.004;
use strict; # enforce declarations and quoting
use CGI qw(:standard); # import shortcuts
use Fcntl qw(:flock); # imports LOCK_EX, LOCK_SH, LOCK_NB

sub bail { # function to handle errors gracefully
my $error = "@_";
print h1("Unexpected Error"), p($error), end_html;
die $error;
}

my(
$CHATNAME, # name of guestbook file
$MAXSAVE, # how many to keep
$TITLE, # page title and header
$cur, # new entry in the guestbook
@entries, # all cur entries
$entry, # one particular entry
);

$TITLE = "ShOc News Board";
$CHATNAME =
"/usr/local/etc/httpd/vhosts/arcticgecko.com/htdocs/clan/membersonly/chatf
ile"; # wherever makes sense on your system
$MAXSAVE = 100;

print header, start_html($TITLE), h1($TITLE);

$cur = CGI->new(); # current request
if ($cur->param("message")) { # good, we got a message
$cur->param("date", scalar localtime); # set to the current time
@entries = ($cur); # save message to array
}

# open the file for read-write (preserving old contents)
open(CHANDLE, "+< $CHATNAME") || bail("cannot open $CHATNAME: $!");

# get exclusive lock on the guestbook (LOCK_EX == exclusive lock)
flock(CHANDLE, LOCK_EX) || bail("cannot flock $CHATNAME: $!");

# grab up to $MAXSAVE old entries, newest first
while (!eof(CHANDLE) && @entries < $MAXSAVE) {
$entry = CGI->new(\*CHANDLE); # pass the filehandle by reference
push @entries, $entry;
}
seek(CHANDLE, 0, 0) || bail("cannot rewind $CHATNAME: $!");
foreach $entry (@entries) {
$entry->save(\*CHANDLE); # pass the filehandle by reference
}
truncate(CHANDLE, tell(CHANDLE)) ||
bail("cannot truncate $CHATNAME: $!");
close(CHANDLE) || bail("cannot close $CHATNAME: $!");

print hr, start_form; # hr() emits html horizontal rule: <HR>
print p("<b>Name:</b>", $cur->textfield(
-NAME => "name"));
print p("Message:", $cur->textfield(
-NAME => "message",
-OVERRIDE => 1, # clears previous message
-SIZE => 50));
print p(submit("send"), reset("clear"));
print end_form, hr;

print h2("Prior Messages");
foreach $entry (@entries) {
printf("%s [%s]: %s",
$entry->param("date"),
$entry->param("name"),
$entry->param("message"));
print br();
}
print end_html;

Thanks in advance for your time and thank you for your help.

Regards,

*NAME-DELETED* *NAME-DELETED*
A:
You could not find any hexa code, because there is none. The white
background and black text is the default of the browser that you use.

See the following line:

print header, start_html($TITLE), h1($TITLE);

This uses functions from the CGI module to produce the start of the HTML
output. I recommend that you read the CGI.pm module documentation. I am
not familiar with this part of CGI.pm I used CGI.pm to parse CGI
variables, but I allways preferred to create the HTML output "by hand".

If you want that then replace the line above with the one:

print <<END;
<HTML>
<HEAD><TITLE>$TITLE</TITLE></HEAD>
<BODY BGCOLOR="here comes the hexa code of the background">
<FONT COLOR="here comes the hexa code of the character color">
END

regards,
Peter

[ back to toc ]