PDA

View Full Version : newbie problem :P



Neverm1nd
June 13th, 2001, 12:31
I'm having problems with my first cgi script. I'm a total newbie, so the complete code probably doesn't make sense. I keep getting an internal server error, whatever I do. I stole some code from a counter and made the script like this:

------------------------------------------------------
#!/usr/bin/perl
# (I'm with F2s)

#page.cgi?bgcolor&fgcolor

sub get_query {
my $command;
my $bgcolor;
my $fgcolor;

if ($ENV{'QUERY_STRING'} ne '') {
$command = "$ENV{'QUERY_STRING'}";
} else {
#must have command line info to operate
error("No command line information");
}

if ($command =~ /(.*)&(.*)/) {
$bgcolor = $1;
$fgcolor = $2;
} else {
error("whatever");
}

#return
($bgcolor,$fgcolor);
}

sub build_output {

print "Content-type: text/html\n\n";
print qq|
<html><head><title>test</title></head><body bgcolor="$bgcolor" text="$fgcolor">
text blablabla
</body></html>
|;
}
------------------------------------------------------

can anybody help me out? Thx. in advance :p

Greetz, Neverm1nd

Neverm1nd
June 13th, 2001, 12:33
Well, maybe handy to explain the purpose of the script:
I want to be able to call the script with page.cgi?black&white, and then the script must create a page with that fore- & backgroundcolors

lucifer
June 14th, 2001, 04:23
couple of changes



#!/usr/bin/perl

my $command;
my $bgcolor;
my $fgcolor;

if ($ENV{'QUERY_STRING'} ne '') {
$command = "$ENV{'QUERY_STRING'}";
}

if ($command =~ /(.*)&(.*)/) {
$bgcolor = $1;
$fgcolor = $2;
} else {
# else set default
$bgcolor = "black";
$fgcolor = "white";
}
print "Content-type: text/html\n\n";

# make sure this is all on the same line
print qq| <html><head><title>test</title></head><body bgcolor="$bgcolor" text="$fgcolor"> text blablabla </body></html> |;



part of problem was you need to output something to the browser even if it's a blank page a request was made so you need to give a responce

Neverm1nd
June 14th, 2001, 06:11
thanx!

thanks for helping me out lucifer!!!
it works perfect :)

Greetz, Nevermind

lucifer
June 14th, 2001, 11:57
be pleased these threads can run on for pages sometimes ;)