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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I produce more than one http-equiv from start_html 2

Status
Not open for further replies.

RiggsFolly

Programmer
Aug 24, 2005
8
GB
Hi,

I am a Perl newbie but an old coder so I hope this is quite simple for you perl pro's.

I am trying to get start_html(.......) to produce more than one http-equiv line in the generated html, but failing dismally.

I would like the following 3 lines:-
Code:
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-language" content="en-GB" />

The only line that actually makes it to the xhtml is:-
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

The code I am using is :-
Code:
	print $q->header(-charset=>'UTF-8');
	print $q->start_html(	-title=>'(Pro Coat - Order Entry)',
							-encoding=>'utf-8',
							-meta=>{ 'keywords'=>'Pro Coat, ProCoat, non slip, non-skid, coating',
										'copyright'=>'copyright 2005 PROCOAT',
										'authors'=>'SUNVIVA Ltd',
										'channel'=>'installers',
										'date'=>'20050824',
										'description'=>'Pro Coat data entry form, for the production of a printable PROFORMA invoice',
										'robots'=>'index follow noarchive'										
										},
							-head=>meta({-http_equiv => 'Content-Language',-content=>'en-GB'}),
							-head=>meta({-http-equiv => 'Content-Type', -content => 'text/html', -charset => 'utf-8'}),
							-head=>meta({-http-equiv => 'content-style-type', content=>'text/css'}),
							-head=>[
                        Link({-rel=>'stylesheet',-type=>'text/css',-href=>'../css/page.css',-media=>'screen'}),
								Link({-rel=>'stylesheet',-type=>'text/css',-href=>'../css/proforma.css',-media=>'screen'}) 
			     				]
		     			);

What actually makes it to the xhtml is:-
Code:
<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	 "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] lang="en-US" xml:lang="en-US">
<head>
<title>(Pro Coat - Order Entry)</title>
<meta name="authors" content="SUNVIVA Ltd" />
<meta name="keywords" content="Pro Coat, ProCoat, non slip, non-skid, coating" />
<meta name="date" content="20050824" />
<meta name="copyright" content="copyright 2005 PROCOAT" />
<meta name="robots" content="index follow noarchive" />
<meta name="channel" content="installers" />
<meta name="description" content="Pro Coat data entry form, for the production of a printable PROFORMA invoice" />
<link type="text/css" media="screen" rel="stylesheet" href="../css/page.css" />

<link type="text/css" media="screen" rel="stylesheet" href="../css/proforma.css" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

Also a little wierd is that the one line that does make it to the xhtml get there even if I remove all 3 of the -head=>meta ... lines.


Can somebody put me on the right track please.

Also a recomendation for a good Perl book would be useful as I am not finding the online docs a great teaching aid.

Thanks
 
Hi

Use an array :
Code:
print start_html( -head=> [
  meta( {-http_equiv => 'Content-Language',-content=>'en-GB'} ),
  meta( {-http_equiv => 'Content-Type', -content => 'text/html', -charset => 'utf-8'} ),
  meta( {-http_equiv => 'content-style-type', content=>'text/css'} )
] );

Beside this, you had typos too. Wrote [tt]http_equiv[/tt] with dash, twice.

Feherke.
 
I don't use cgi.pm much for this kind of thing - I find it easier to just [tt]print[/tt] the HTML that I want. However, you coud try
Code:
...
-head=>meta({-http_equiv => 'Content-Language',-content=>'en-GB'},
            {-http-equiv => 'Content-Type', -content => 'text/html', -charset => 'utf-8'},
            {-http-equiv => 'content-style-type', content=>'text/css'}),
...
However, I'd take a step back and consider what you really want to do. [tt]http-equiv[/tt] <meta> tags are used to send stuff to the browser that should really be sent in the http header. Often, with static pages and shared hosting, we can't control the actual http headers sent with our files, so the <meta http-equiv=""> workround is a handy workround.

With CGI programs, you control what's sent in the header, so you don't need any <meta> tags to do the job. So clear out all that meta stuff and replace your existing call to the header object with this:
Code:
print $q->header(-type=>"text/html",
                 -content_style_type=>"text/css",
                 -content_language=>"en-GB",
                 -charset=>'UTF-8');



-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks ferehke.

Thanks Chris.

Both ways appear to work.

Chris
As I cant see the header when I look at the page source from a browser, where can I find some good Doc on the CGI::. I had an idea those bits should go in the header() call but could find no comprehensive doc on CGI except the rather poor stuff at which is repeated ad-infinitum around the web and is probably obsquiring any other stuff in my searches.

Thanks again.
 
Chris,

I see a problem with the info you gave me. I only mention this as it may help me increase my understanding.

I was coding UK pound signs as the £ (pound char) and not the escape sequence. When I use your solution they change to ? (question marks). Do you know what else needs to be in the header to set them back to £ (pound signs)?

I dont mean to be a pain, it just comes naturally!!
 
Hi

Could you paste the HTTP headers, the webserver send out ? For example the output of :
Code:
wget -S --spider [URL unfurl="true"]http://example.com/cgi-bin/my.pl[/URL]

By the way, what operating system and webserver are you using ?

Feherke.
 
Hi feherke,

??? I guess you are a unix bod. Oh looked at your site, you obviously are.

I am using Win XP SP2 and ABYSS X1 v2.0.6. The server is also on my machine (its my test server).

Dont know wget, guess its a unix tool.

What are you trying to solve by looking at the servers http headers??

 
feherke,

read your email, its easier than this and we wont clutter up the thread with chatter.

 
Hi

RiggsFolly said:
What are you trying to solve by looking at the servers http headers??

As I understand, now you use the method proposed by Chris, so the charset information is in the HTTP header. You wrote that you have problem with special characters. So logically the next step in debuging is to see the HTTP header sent by the webserver.

Feherke.
 
feherke,

Hey that firefox tool is a bit good. Thanks for that idea it will be very useful.

Well actually I am using your solution, Thanks again, as Chris's caused that currency sign problem.

Here are a set of headers from a call (post) to the script that paints a page with the currency symbols in.

Using your solution.

Code:
[URL unfurl="true"]http://localhost/PROCOAT-DEV/cgi-bin/invpr.pl[/URL]

POST /PROCOAT-DEV/cgi-bin/invpr.pl HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: [URL unfurl="true"]http://localhost/PROCOAT-DEV/cgi-bin/getinvpr.pl[/URL]
Authorization: Basic Y2hyaXNyaWdnbWlsbmVyQHlhaG9vLmNvLnVrOm0yNm5sMjRuZw==
Content-Type: multipart/form-data; boundary=---------------------------23281168279961
Content-Length: 1859
-----------------------------23281168279961
########################
QUERY STRING REMOVED
########################

HTTP/1.x 200 OK
Content-Type: text/html; charset=ISO-8859-1
Connection: Keep-Alive
Keep-Alive: timeout=30000, max=15
Transfer-Encoding: Chunked
Date: Wed, 24 Aug 2005 14:29:02 GMT
Server: Abyss/2.0.6-X1-Win32 AbyssLib/2.0.6

Here is the headers generated using Chris's solution

Code:
POST /PROCOAT-DEV/cgi-bin/invpr.pl HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: [URL unfurl="true"]http://localhost/PROCOAT-DEV/cgi-bin/getinvpr.pl[/URL]
Authorization: Basic Y2hyaXNyaWdnbWlsbmVyQHlhaG9vLmNvLnVrOm0yNm5sMjRuZw==
Content-Type: multipart/form-data; boundary=---------------------------491299511942
Content-Length: 1821
-----------------------------491299511942
###########################
QUERY STRING REMOVED
###########################
-----------------------------491299511942--

HTTP/1.x 200 OK
Content-Language: en-GB
content-style-type: text/css
Content-Type: text/html; charset=UTF-8
Connection: Keep-Alive
Keep-Alive: timeout=30000, max=15
Transfer-Encoding: Chunked
Date: Wed, 24 Aug 2005 14:32:45 GMT
Server: Abyss/2.0.6-X1-Win32 AbyssLib/2.0.6


What can you gleen from this? I can see a big difference.
 
Hi

In the first response you can see the default charset sent by the webserver itself, based on it's settings :
[tt][highlight #cff]Content-Type: text/html; charset=ISO-8859-1[/highlight][/tt]
In this case the charset specified inside the HTML document throug the [tt]meta[/tt] tag is ignored.

In the second response is the charset your script told to the webserver :
[tt][highlight #cff]Content-Type: text/html; charset=UTF-8[/highlight][/tt]

As the page is displayed correctly in the first case, this means that the file was edited in iso-8859-1, not in utf-8. So if you change that, the Chis's solution must work as well :
Code:
print $q->header(-type=>"text/html",
                 -content_style_type=>"text/css",
                 -content_language=>"en-GB",
                 -charset=>'[red]ISO-8859-1[/red]');

Feherke.
 

Ok Chris's solution now works as well.
Thanks for your time.

I wish I could say I totally understood but I dont think I do.

Does this mean it is safer to code the escape code in the perl script or would that have given a similiar problem if I saved the code in ISO-8859-1 and sent the charset as = UTF-8?

Am I correct in assuming that the escape code I use in html or perl must match the charset I tell the browser to use when decoding the html. So I should send the charset I save the html or perl in to ensure it always translates to the correct character on the browser?

If this is correct then I have definitely learned something useful today.
 
Hi

Yes, that's the point. The charset information must match the character set you used during the editing.

I prefer to send this kind of information in the HTTP header, because this way the server's default ( the one with the higher priority ) will be overwritten with correct information. This is important if the available documents have different charsets. But this works only for CGI, not for static HTML files. So, as possible, disable the sending of default charset in the webservers configuration.

But when someone save the document, the HTTP headers are not saved, so is necessary to put them in the HTML header too, in some meta tags. The W3C validator also require a meta with content-type and charset.

As a conclusion, as possible, put it in both places. So use Chris and my solutions together.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top