 |
 |
Need Help Configuring My HTTP Headers
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
I'd like to configure my HTTP headers for my website to force a particular encoding (UTF-8) for those visiting my site. I figure I have to use SSH and the command line (I have offsite hosting). Does anybody know how to do this or have a link to a good book or tutorial that will let me do this quickly? My undying gratitude in advance.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2004
Status:
Offline
|
|
|
(Last edited by leira; Jun 27, 2005 at 06:38 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
Let me back up. I'm already using this code:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The trouble is, the browsers don't seem to be obeying the charset designation because fractions don't display properly (see also this thread). So I had the idea that maybe by editing the HTTP headers I could force the browsers to obey the charset.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
You can send it along with the Content-Type header:
Content-Type: text/html; charset=utf-8
Also, make sure that your files are indeed being saved as UTF-8.
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
Originally Posted by Wevah
You can send it along with the Content-Type header:
Content-Type: text/html; charset=utf-8
Also, make sure that your files are indeed being saved as UTF-8.
If you read the immediately previous post to yours, isn't that exactly what I said I was doing already? Also, what do you mean by "saved as utf-8"? — Surely you are not referring to filetype? I just save them as text with the .php extension like I've always done. Is there another step of which I am not aware?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
a) I'm talking about the actual Content-Type HTTP header, not the HTTP-equiv meta tag.
b) Yes, you need to make sure that your files are being saved with the UTF-8 character encoding, and not MacRoman or ISO-8859-1 or something else. I am not referring to filetype.
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
Originally Posted by Wevah
a) I'm talking about the actual Content-Type HTTP header, not the HTTP-equiv meta tag.
So, you mean something like this?
Code:
<?php
header ("Content-Type: text/html; charset=utf-8");
?>
I did try that, but I got an error message saying headers had already been sent. Do I have to figure out how to configure my server not to react that way?
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2004
Status:
Offline
|
|
that link i put up before suggests that the prefferred method is to make your web server send the header and gives you a hint about how to make apache do it. If you use something else check the docs for the details.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
You have to make sure to call the header() function before anything is output to the browser. I'm guessing that the file's data simply isn't encoded correctly, though (a blameless mistake, really).
Do you have an example file I could peek at to check?
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
Well, I created a file called .htaccess and uploaded it containing a line that reads:
Code:
AddType 'text/html; charset=utf-8' html
but it does not achieve what I hoped, that my Unicode characters would be more likely to display properly.
(Last edited by selowitch; Jun 28, 2005 at 06:27 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status:
Offline
|
|
One more thing to note: there are a lot of people using browsers (*Internet Explorer*) that do not properly use Unicode, and who's default fonts do not have much in the way of non-ASCII-range characters. There is simply no way around that. And older version of Windows only install the extra characters when you install the language packs.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
Originally Posted by larkost
One more thing to note: there are a lot of people using browsers (*Internet Explorer*) that do not properly use Unicode, and who's default fonts do not have much in the way of non-ASCII-range characters. There is simply no way around that. And older version of Windows only install the extra characters when you install the language packs.
Exactly. Which begs the question of why either there are not a series of cross-platform OpenType fonts that are automatically installed with every browser in the universe (Windows, Mac, or Linux) or why we even rely on the system the browser is on to provide the fonts. There ought to be some kind of embedded font technology where we can pay for and deploy fonts *on the server*. Now there's a new source of revenue for the font foundries, and it would really open thing up and end nuisances like this. It's so mind-bogglingly stupid that it keeps me up at night.
Dammit, this is so frustrating. I hate not being able to display fractions properly, and I hate horsey-looking workarouinds like <sup>1</sup>/<sub>4</sub> and CSS hacks.
Related Thread: Even when the characters I want actually exist, why the heck aren't they at least rendered in the same bloody typeface??? Auuughh!!!!
(Last edited by selowitch; Jul 1, 2005 at 01:34 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
Get used to the frustration.
There is no good answer. there are still too many differences between architectures which is the reason for html in the first place.
Originally Posted by selowitch
Exactly. Which begs the question of why either there are not a series of cross-platform OpenType fonts that are automatically installed with every browser in the universe (Windows, Mac, or Linux)
Yeah, it sucks. We're stuck with about 11 fonts that are truly cross platform. Remember that not all fonts can display at all sizes. Some browsers try to alter the size on their own and some will replace the font with one they think is similar. So if you specify 11px you can get a different result than 12px;
Originally Posted by selowitch
or why we even rely on the system the browser is on to provide the fonts.
There is a system for specifying a font along with a url for the browser to go get it, but nobody uses it because it is a hassle and you can't rely on it to work everywhere. 1. fonts can be pretty big and take a while to download. 2. certain systems and or applications can't install and use a font on the fly.
Originally Posted by selowitch
Dammit, this is so frustrating. I hate not being able to display fractions properly, and I hate horsey-looking workarouinds like <sup>1</sup>/<sub>4</sun> and CSS hacks.
have you tried the codes?: ½ ¼ &f rac34;
here's a page with workarounds for math issues: http://www.cs.tut.fi/~jkorpela/math/
If you are trying an alternate encoding remember to save your php file in that encoding - use bbedit or subethaedit to do this. the file and the encoding have to match.
You are on the right track with
<?php
header ("Content-Type: text/html; charset=utf-8");
?>
this has to be used -before- the php file sends -anything- to the browser. Put it on the first line, don't put it in a file included inside another file, etc.
Even if you do have success with one mac or pc there is no guarantee that it will work on another. It depends on the browser, system settings, OS version, etc.. You ultimately have no control over it which is why people give up and use pictures.
Have fun.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status:
Offline
|
|
Originally Posted by selowitch
If you read the immediately previous post to yours, isn't that exactly what I said I was doing already? Also, what do you mean by "saved as utf-8"? — Surely you are not referring to filetype? I just save them as text with the .php extension like I've always done. Is there another step of which I am not aware?
The file might not be encoded as UTF-8. Open it in an app like SubEthaEdit, which will tell you the encoding at the bottom of the window. Manually change it to UTF-8 if necessary.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
Originally Posted by wataru
The file might not be encoded as UTF-8. Open it in an app like SubEthaEdit, which will tell you the encoding at the bottom of the window. Manually change it to UTF-8 if necessary.
Thanks, wataru. Who'da thunk it?
Originally Posted by Gavin
If you are trying an alternate encoding remember to save your php file in that encoding - use bbedit or subethaedit to do this. the file and the encoding have to match.
This doesn't make intuitive sense, but I believe you nonetheless.
Has anybody actually done this and have it make any typographic difference? Every instinct and prior assumption tells me the encoding of the file itself is irrelevant and only the code within matter. If it has the extension .htm or .html, it gets read as HTML; if .php, then as PHP, etc. Apparently I'm wrong, though. It wouldn't be the first time, God knows.
Originally Posted by Gavin
have you tried the codes?: ½ ¼ &f rac34;
Uh-huh. No better than specifying them numerically as far as I can see. Whose brilliant idea was it to put one-half, one-quarter, and three-quarters in the Latin-1 Supplement range and the rest of the fractions under Number Forms? It seems like one guy was working that first day in one font, then months later some other turkey comes along to do the Number Forms and doesn't go and look at what typeface was used for the first three. And neither of them bothered to see what the parent typeface even looks like. What were they thinking/smoking?
*sniff* *sob* *sniff*
So even if we could persuade all of the browser makers to include at least one font that has all the fractions characters, chances are they'd still be screwed up and typographically incorrect! No one ever worries that a string like "abcdefghijklmnopqrstuvwxyz" styled with the same font will actually display correctly in that font — so why do we have to have this anxiety in the case of fraction glyphs?
Originally Posted by Gavin
You ultimately have no control over it which is why people give up and use pictures.
Never! Death first! Actually, maybe I could send the text from PHP over to ImageMagick and generate a .gif of the text I need automatically. Hmmmmm.
(Last edited by selowitch; Jul 1, 2005 at 01:54 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status:
Offline
|
|
Originally Posted by selowitch
Has anybody actually done this and have it make any typographic difference? Every instinct and prior assumption tells me the encoding of the file itself is irrelevant and only the code within matter. If it has the extension .htm or .html, it gets read as HTML; if .php, then as PHP, etc.
No no no, he's talking about the same thing as I am. Encoding != format. HTML and PHP are formats (in a sense; regardless, they're not encodings). UTF-8 and ISO-8859 are encodings. He's suggesting you make the file the same encoding as what you are claiming it to be in the header, which is UTF-8.
Example:
This page has a randomly-chosen haiku in Japanese on it. The actual PHP document itself is encoded as UTF-8. What happens when we force it to identify itself as Shift-JIS? How about ISO-8859-1? How about EUC-JP?
As you can see, if the encoding declared in your document is not the same as the encoding the document is actually in, you will get bad things happening.
(Last edited by wataru; Jul 1, 2005 at 10:49 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status:
Offline
|
|
Originally Posted by wataru
No no no, he's talking about the same thing as I am. Encoding != format.
I understand that. I just never thought that the encoding of the document file itself would make a difference. I'll try it.
EDIT: OK, While I'm sure it's good practice to check/change the encoding of a Unicode document prior to uploading it, it doesn't make a difference in my particular typography issue, unfortunately. The problem lies, it seems, in the fonts themselves. The solution is to convince the browser makers to bunlde a font along with their browsers that includes a wide character set and which is installed on all platforms. I'm not holding my breath, but I'm very angry.
(Last edited by selowitch; Jul 2, 2005 at 08:28 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
Originally Posted by selowitch
Whose brilliant idea was it to put one-half, one-quarter, and three-quarters in the Latin-1 Supplement range and the rest of the fractions under Number Forms?
...
What were they thinking/smoking?
They were smoking that funky TRS 80 back in 1978
All these things go back to when computers had very limited resources so you couldn't fit everything in. Mostly they just made available the characters on your standard typewriter keyboard - some of the fancier ones even had a couple of your more common fractions.
Originally Posted by selowitch
Every instinct and prior assumption tells me the encoding of the file itself is irrelevant and only the code within matter. If it has the extension .htm or .html, it gets read as HTML; if .php, then as PHP, etc.
As wataru mentioned, encoding is not related to the scripting language or if the file has html in it. Encoding has to do with how the actual text data is saved to disk, and every OS does it differently. It all gets converted to numbers, in one encoding an A may be stored as number 123 but in another encoding it gets stored as 45692. Every computer company had their own extensions to ASCII and if you wanted your computer to work in Korean then ASCII wasn't going to cut it, so there are lots of different encodings. Generally they all use the same code for basic stuff like a-z A-Z and numbers, but the codes start to differ when you get to stuff like angstrom or E with an accent. So when you switch from Latin1 to Mac Roman the letters work but things like a eruo char and fractions break - you get those little boxes or greek or something.
unicode was supposed to be the One True Encoding to fix all of this madness but...
Originally Posted by selowitch
No better than specifying them numerically as far as I can see.
I'd go with the html codes. Your current problem is exactly what they are for. php probably has a function to convert then for you, or maybe someone has a class.
here's one for perl: http://search.cpan.org/~lbrocard/HTM...ML/Fraction.pm
So even if we could persuade all of the browser makers to include at least one font that has all the fractions characters, chances are they'd still be screwed up and typographically incorrect!
Actually, maybe I could send the text from PHP over to ImageMagick and generate a .gif of the text I need automatically. Hmmmmm.
interesting idea. Probably be more work than it's worth but you might rig something up with html2pdf and imagemagick. http://user.it.uu.se/~jan/html2ps.html http://www.rustyparts.com/pdf.php
in the short run you might just define in css a huge list of fonts that can display your fractions. That way you increase the odds that any given system has one of them. I'm sure that some website somewhere lists the fonts that come with windows and mac and can tell you if they have the characters you need.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2004
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|