Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

backgrounds in cgi? 1

Status
Not open for further replies.

rickict

IS-IT--Management
Apr 29, 2005
18
GB
im just learning html and cgi.

i've got a very simple and unfinished test script that i'm writing to learn things .
the problem i have at the moment is i cant seem to get a background picture to work with the script although it works with any standard html.?
this is the full script .
any other tips will be appreciated. all critics welcome.

#!c:/perl/bin/perl.exe
print "Content-type: text/html\n\n";


$htmlForm = <<EOS;
<html>
<head>
<title>send text form</title>
</head>
<body BACKGROUND="NOLF2b_12.jpg">
<form method="POST"
action="<b3>Pick a number<br /></b3>
<input type="text" name="text" size="25">
<input type="submit" value="Hit it">
</form>
<body>
</html>
EOS
print $htmlForm;


print "<html>";
if ( $ENV{'REQUEST_METHOD'} eq 'POST'){
$text = <STDIN>;
}

print "$text";

print "</html>";
 
unless the image is in the same diectory as the script this will not work (and still may not work anyway depending on the server setup). Put the image in a folder aboe the cgi-bin and link to that folder:

<body BACKGROUND="../images/NOLF2b_12.jpg">
 
hi kevin
i've rewritten to include a path and placed the image in a folder but still it doesn't work.
before i had the image in the same folder as the cgi script.
you said about how the server is set up? im using apache with winXP default setup.
as i mentioned the BACKGROUND= tag worked fine in a normal HTML file but not in the cgi?? is this normal? that they can work differently.
 
there really is no difference between displaying an image from a script generated page or a static html page. You just have to make sure the URL/path to the image is correct, if you are unsure of the path use the full url to the image file:

<body background="
if that doesn't work then you have different problems.

"localhost" is generally the default domain name when running apache locally on your PC.
 
you really should be using CSS anyway for html pages as much as possible, hard coding attributes directly into html tags is
a good 4 to 5 years behind the times. Plus using CSS just makes updating or editing layout/appearance so much easier.
 
$htmlForm = <<EOS;
<html>
i changed it to use the full localhost url as below. if your saying that there is no reason why this should not work then
thats fine, i can look at other areas. as for CSS, im getting there!! but is there not compatability problems with some browsers? that are preventing people from using them.
or, is it common practice now? maybe its just my learning material is out dated? thanks for your help...rick


<head>
<title>send text form</title>
</head>
<body BACKGROUND="<form method="POST"
action="<b3>Pick a number<br /></b3>
<input type="text" name="text" size="25">
<input type="submit" value="Hit it">
</form>
<body>
</html>
EOS
print $htmlForm;
 
Try closing your <body> tag. You currently have :
Code:
</form>
<body>
</html>
instead of:
Code:
</form>
<[b]/body[/b]>
</html>

 
Code:
<body BACKGROUND="[URL unfurl="true"]http://localhost[/URL][b]/cgi-bin/[/b]images/NOLF2b_12.jpg">
Most hosts are set up not to return files from within the [tt]cgi-bin[/tt] directory or its subdirectories. Files located there are either executed or not returned at all.

Put the image in a directory outside your cgi-bin directory, and write a suitable URL. For example, if you put it in a directory called "images" just below your document root, put this:
Code:
<body BACKGROUND="/images/NOLF2b_12.jpg">

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
but is there not compatability problems with some browsers? that are preventing people from using them.
or, is it common practice now?

Hopefully this is not too off-topic...

CSS is supported by all modern browsers although there are some quirks between browsers in the way they calculate certain things (like margins and borders), and there is some browser specific (just like html) CSS code (like filters). But CSS is very simple to learn, it's pretty much just HTML-ish attributes stored in a seperate document.
 
CSS isn't as broken across browsers as it was just a year or two ago, and most of the problems have been documented well enough that there are little hacks available if you search. Just be aware of your DOCTYPE and how that will affect browsers' interpretations. IE is the most famous culprit, but others try to model its behavior to achieve more consistent rendering with older pages.



________________________________________
Andrew

I work for a gift card company!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top