use of CSS in CGI generated docs, Impossible ?

N

navid.boarder

hei all,

i can't get Css applied to my cgi-generated page. also no images are
shown.
funny part is that if I just open the HTML file it shows images and
gets Css applied. but when i open the same HTML file using CGI open
function all images are X's and no Css is applied.
and i am sure that trouble is not because of place of my files.

here's my code for lifesavers to read:
--------------------------------------------------------------------------------------
#!c:/perl/bin/perl
use CGI;
use CGI::Carp qw( fatalsToBrowser );
use DBI;


$query = new CGI;


my ($session_id, $dbh, $sth, $action, $product_id, $quantity);

&show_new;

sub show_new {

open (FILE, "ch100.html") or die "cannot open HTML source";

$title = <FILE>;
for $line (<FILE>) {
print $line;
}
close FILE;
}

--------------------------------------------------------------------------------------

please note that above code doesn't really do anything, because I've
cut unnecessary parts.

Now i give some of ch100.html's code:

--------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">

<html>

<head>

<meta http-equiv="Content-Type" Content="text-html; charset=UTF-8">

<title>chair </title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>

<body id="lit">
 
U

usenet

anyone has any idea? anyone got the message?

Your CGI script is probably running in a directory called "cgi-bin".
Your HTML uses relative paths to find the stylesheet, ie:
<link rel="stylesheet" type="text/css" href="css/main.css" />

To resolve the relative path from your cgi-bin, your webserver would be
looking for:

/path/to/my/cgi-bin/css/main.css

I doubt that's where your css file is located (I suspect your 'css'
directory is beneath your DocumentRoot).

You can (probably) fix this with an absolute path:

<link rel="stylesheet" type="text/css" href="/css/main.css" />

This isn't really a Perl question, by the way.
 
A

A. Sinan Unur

(e-mail address removed) wrote in
i can't get Css applied to my cgi-generated page. also no images are
shown.

Of course, this has absolutely nothing whatsoever to do with Perl.

Please read the posting guidelines for this group.
and i am sure that trouble is not because of place of my files.

You are surely wrong.
#!c:/perl/bin/perl

I find it convenient to use the fairly generic and general she-bang

#!/usr/bin/perl

even for scripts on Windows. That way, I can use the same script on
FreeBSD, Linux, and Win XP without any changes.

If you are going to use the object oriented interface, you should
probably write:

use CGI();

so you don't import a whole bunch of names into your script's namespace.

Also,

use strict;
use warnings;

are missing. Use them.
use CGI::Carp qw( fatalsToBrowser );
use DBI;


$query = new CGI;

While this notation looks cute, it is somewhat safer to always use the
-> notation (I know there are names for these, but I can't remember).
The fact is 'new' in Perl is not a keyword, you are just invoking a
method, so use method-invocation syntax.

Do you also write:

#!/usr/bin/perl

use strict;
use warnings;

use CGI();
my $cgi = new CGI;
my $value = param $cgi 'param';

print "$value\n";
__END__

D:\Home\asu1\UseNet\clpmisc> z.pl param=sinan
sinan
my ($session_id, $dbh, $sth, $action, $product_id, $quantity);

Declare variables in the smallest applicable scope.
&show_new;

Unless you know the difference between &show_new and show_new(), and you
need the specific functionality provided by the former, you should use
show_new(). See perldoc perlsub/
sub show_new {

open (FILE, "ch100.html") or die "cannot open HTML source";

No need to use a bareword filehandle here. Note also that using a
relative filename is fragile.

open my $html, 'ch100.html' or die "Cannot open 'ch100.html':$!";

Always include the reason for the failure in the error message.
$title = <FILE>;
for $line (<FILE>) {
print $line;
}

Think about the difference between the loop above versus the preferred
way of doing things:

print while <$fh>;

By using the for loop, you are first reading the whole file into memory,
then printing it line-by-line. Why?
please note that above code doesn't really do anything, because I've
cut unnecessary parts.

And did not include some necessary parts.
Now i give some of ch100.html's code:
....

<link rel="stylesheet" type="text/css" href="css/main.css" />

The href above should refer to an absolute path.
anyone got the message?

Yeah, we got the message alright. Now, you can do the same, and ask CGI
questions in a CGI group, HTML questions in an HTML group, and Perl
questions here.

Sinan
 
R

RedGrittyBrick

Apart from the issues already pointed out, there is one other anomaly in
the posted code that might be a bug (or might be the result of
incosistent pruning to create an example):


hei all,

i can't get Css applied to my cgi-generated page. also no images are
shown.
funny part is that if I just open the HTML file it shows images and
gets Css applied. but when i open the same HTML file using CGI open
function all images are X's and no Css is applied.
and i am sure that trouble is not because of place of my files.

here's my code for lifesavers to read:
--------------------------------------------------------------------------------------
#!c:/perl/bin/perl
use CGI;
use CGI::Carp qw( fatalsToBrowser );
use DBI;

$query = new CGI;
my ($session_id, $dbh, $sth, $action, $product_id, $quantity);
&show_new;
sub show_new {
open (FILE, "ch100.html") or die "cannot open HTML source";
$title = <FILE>;

Since you never print $title, you are losing the first line of your HTML
source.
for $line (<FILE>) {
print $line;
}
close FILE;
}

--------------------------------------------------------------------------------------

please note that above code doesn't really do anything, because I've
cut unnecessary parts.

Now i give some of ch100.html's code:

The above line will not be transmitted by your CGI application.
 
M

Matt Garrish

A. Sinan Unur said:
While this notation looks cute, it is somewhat safer to always use the
-> notation (I know there are names for these, but I can't remember).

Arrow... : )

Matt
 
G

Gunnar Hjalmarsson

A. Sinan Unur said:
If you are going to use the object oriented interface, you should
probably write:

use CGI();

so you don't import a whole bunch of names into your script's namespace.

If that had been the case, wouldn't the CGI POD have mentioned it?

use CGI();
BEGIN { $::symbols = keys %CGI:: }

use CGI;

print "With parens: $::symbols\n",
'Without parens: ', scalar keys %CGI::, "\n";

Outputs:
With parens: 86
Without parens: 87

Not much to make a fuss about, is it? ;-)
 
N

navid.boarder

what the hell is going on in these perl groups?? everybody wants to say
howmuch wrong i was but no one (except (e-mail address removed)) wants to
really solve problems of each other. if any one has found any wrong
coding in my script he should i think, nicely tell me in such a way
that i understand i am beginner and THIS GROUP IS PERL.MISC WHICH MEANS
I CAN POST WHATEVER I WANT ABOUT PERL... :p:p:p

come on guys let's be more practical somebody help me with getting the
thing to work.

Sinan you could be more friendly, especially with large amount of info
you've collected in your head. where r u from? how long have you been
sitting behind your screen? since you were 5?

and you give good explanations, keep it cool.


anyway guys, (e-mail address removed)'s way, with all due respect, did
not work. if you're still interested to help i will appreciate that
greatly,


remember that i cannot show images in browser. Also if you have other
improvements to my code's saftey and such, besides mentioned ones,
please tell those as well.



thanks nerds, be cool
 
R

RedGrittyBrick

what the hell is going on in these perl groups??

It's called consensus. CLPM has a distinct culture. If you want help in
foreign lands, I find it is best to observe local customs. There is a
set of guidelines for CLPM that explain how to get the best out of this
newsgroup. If you ignore the guidelines you are likely to rub people up
the wrong way.

You are using Google groups. Do you know about their guidance:
http://groups.google.com/googlegroups/posting_style.html#summarize
everybody wants to say
howmuch wrong i was

I find that finding out what is wrong is a good step towards writing
something right. YMMV.
but no one (except (e-mail address removed)) wants to
really solve problems of each other.

I'm not sure what you mean by this. I think almost all responders in
this newsgroup want to help people with Perl problems. You just have to
help them to help you by writing your questions well.

if any one has found any wrong
coding in my script he should i think, nicely tell me in such a way
that i understand

If anyone has wrong coding in his script he should I think nicely tell
us in such a way that we can understand.

i am beginner and THIS GROUP IS PERL.MISC WHICH MEANS
I CAN POST WHATEVER I WANT ABOUT PERL... :p:p:p

I am not quite a beginner and this group is comp.lang.perl.misc which
means you can kick, whine and scream all you like but you'll just
alienate most of the people who know the answers you seek.
come on guys let's be more practical somebody help me with getting the
thing to work.

I think that will follow if you'll be more practical in explaining your
Perl problem.
Sinan you could be more friendly, especially with large amount of info
you've collected in your head. where r u from? how long have you been
sitting behind your screen? since you were 5?

and you give good explanations, keep it cool.

For my part, if he gives good explanations, his perceived friendliness
is secondary. In fact I suspect he is friendly but expresses himself in
a brusque manner to avoid wasting time.
anyway guys, (e-mail address removed)'s way, with all due respect, did
not work. if you're still interested to help i will appreciate that
greatly,

I have found that a good way to show your appreciation is by
demonstrating that you have read the posting guidelines for this newsgroup.

http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

I find this is good too

http://www.catb.org/~esr/faqs/smart-questions.html
remember that i cannot show images in browser. Also if you have other
improvements to my code's saftey and such, besides mentioned ones,
please tell those as well.


Unfortunately, I have forgotten your original posting and you didn't
quote any context, so I can't help.


Good luck.
 
S

Sherm Pendley

that i understand i am beginner and THIS GROUP IS PERL.MISC WHICH MEANS
I CAN POST WHATEVER I WANT ABOUT PERL... :p:p:p

Your question was not about Perl. You'd get precisely the same results if
you'd written your CGI in Python, Ruby, C, etc.
come on guys let's be more practical somebody help me with getting the
thing to work.

In practical terms, identifying the "problem domain" is a crucial first
step to solving *any* problem. Someone who's showing you how to do that
is being *very* helpful.

Try this exercise: Create a web page and a stylesheet. Put the web page
in directory /foo on your web server, and the stylesheet in /bar. In
your HTML, link to the stylesheet like this:

<link rel="stylesheet" type="text/css" href="bar.css">

The stylesheet doesn't load. Now, let's suppose you happened to create
this web page with Notepad - would you ask for help about your HTML code
in a Notepad group? Of course not.

What you have is a question about relative URLs in HTML, and how a user
agent handles them. The source of the HTML, be it a Perl CGI, Notepad, or
infinite monkeys with typewriters, isn't relevant.
thanks nerds, be cool

Calling people rude names is a rather odd way to thank them.

sherm--
 
A

A. Sinan Unur

If that had been the case, wouldn't the CGI POD have mentioned it?

Sorry for the late response. I had to try to remember where I had seen
that recommendation. Lucky for me, O'Reilly put just the document I was
looking for online:

http://modperlbook.org/html/ch04_03.html says:

use CGI ( );

....

As with all modules we preload in the startup file, we don't import
symbols from them because they will be lost when they go out of the
file's scope.

So, I have adopted that style as a general rule of thumb. I had not
actually examined what happens with CGI.pm.

Sinan
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g14g2000cwa.googlegroups.com:
where r u from?

Huh? It takes only eleven keystrokes to find that out.

Besides, what's that got to do with anything?
how long have you been sitting behind your screen? since you were 5?

Actually, since I was 8.
thanks nerds, be cool

Bye.

Sinan
 
G

Gunnar Hjalmarsson

A. Sinan Unur said:
Sorry for the late response. I had to try to remember where I had seen
that recommendation. Lucky for me, O'Reilly put just the document I was
looking for online:

http://modperlbook.org/html/ch04_03.html says:

use CGI ( );

...

As with all modules we preload in the startup file, we don't import
symbols from them because they will be lost when they go out of the
file's scope.

So, I have adopted that style as a general rule of thumb.

I have adopted it for mod_perl startup files.
I had not actually examined what happens with CGI.pm.

I wondered about it because I remembered that the CGI POD very clearly
points out that you need to import function names explicitly to be able
to use the function oriented interface. Btw, no well-written modules
export "a whole bunch of names" by default, do they?

I have seen you mention it a couple of times as regards CGI.pm, and
personally I think you overdo it by mentioning it 'by default'. Readers
might miss more important points if you do.
 
A

A. Sinan Unur

....

I have seen you mention it a couple of times as regards CGI.pm, and
personally I think you overdo it by mentioning it 'by default'.
Readers might miss more important points if you do.

Well put. I'll keep that in mind. Thank you.

Sinan
 
T

Tad McClellan

what the hell is going on in these perl groups??


Try asking a Perl question, and the response is likely to be different.

everybody wants to say
howmuch wrong


This is a newsgroup for discussing Perl programming, you did not
have a Perl programming problem.

i was but no one (except (e-mail address removed)) wants to
really solve problems of each other.


See?

Asking a web server question in a programming language newsgroup
is a bad idea. Bad for you, no answers. Bad for us, no Perl content.

i am beginner


Here is a hint, don't shout at people...

and THIS GROUP IS PERL.MISC WHICH MEANS
I CAN POST WHATEVER I WANT ABOUT PERL... :p:p:p


.... like that.

come on guys let's be more practical


It is *you* who are being impractical.

If there are no newsgroup topics, then we'd have tens of thousands
of messages in the MegaGroup, each day!

somebody help me with getting the
thing to work.


Ask web server questions in a web server newsgroup.

Sinan you could be more friendly,


Rudeness begets rudeness.

You started it.

if you're still interested to help


I don't think so.

So long!
 
N

navid.boarder

I knew I should ask my question in CGI group, dummies. But there is not
such a group in english, there's only one in german.

and if i do CGI and i donot find CGI group i'll find a perl group
because i am doing CGI in perl, like i did.

<BREAKING NEWS> fortunate you all were, I just found a group called
perl.beginners.cgi and i am finding my answers there. just wish i get
my answers otherwise i'll get more nasty with you.


So long Tad, Sherm, Sinan (SINAN means what?) , Red Brick and Todd.

be cool,
 
A

axel

What notation?
Maybe I should have asked what # is called in English.
On second thought, let's please not go there.

Well, hash in the UK, the pound sign in America.

Many UK keyboards have an actual pound sign in place of
the hash... that can cause problems in coding... of
course most people in the UK have no reason to use the
hash key, although they do have a very good reason to use
the pound sign, which very few people in America have.

Axel
 
A

axel

i can't get Css applied to my cgi-generated page. also no images are
shown.
funny part is that if I just open the HTML file it shows images and
gets Css applied. but when i open the same HTML file using CGI open
function all images are X's and no Css is applied.
and i am sure that trouble is not because of place of my files.
"http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
<title>chair </title>
<link rel="stylesheet" type="text/css" href="css/main.css" />

Try:

<set linkstyle="foo.css">


Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top