Proper use of PHP: header('Content-language: ...');
aside the obvious fashion of setting the language of a page:
<meta name="language" content="de"><html lang="de">
I recently found an amazing aspect typical to only the programming language of PHP that could enables developers to set the language at the very top of PHP files:
<?php
/* Set and开发者_开发百科 pre-define the language in the header;
* Eliminating guesswork for the Header language.
*/
header('Content-language: de');
?>
Two questions arise eveidentaly to the PHP programmer:
Main Question: When should one set the language in a PHP header?
SideQ1: Big websites don't bother using it: why don't they?
SideQ2: Do search engines listen to this and if so, what implications does this PHP header have?
Shorter answer: Don't bother, cause browsers typically ignore it.
Longer answer: The W3C recommends using the lang
attribute in HTML over the Content-Language
header in HTTP:
http://www.w3.org/International/geo/html-tech/tech-lang.html#ri20040808.110827800
Rationale: User agents tend to ignore the header or implement it inconsistently.
Plus, the lang
attribute is more flexible. If you have some content in one language and other in another, you can specify that precisely, like so:
<body>
<div lang="en" xml:lang="en">
<h1>Welcome!</h1>
<p>Lots of text in English...</p>
</div>
<div lang="fr" xml:lang="fr">
<h1>Bienvenue !</h1>
<p>Beaucoup de texte en français...</p>
</div>
</body>
Taken from: http://www.w3.org/International/geo/html-tech/tech-lang.html#ri20040728.121403792
I don't know about search engines.
You can use this header for informational purposes. But it's primarily meant for content negotiation.
Each http URL can transparently refer to different resources. Depending on a clients Accept: and Accept-Language: header, the server can send a specific variant of a resource. And that's when it is advisable that such descriptive headers are included.
If it's used in that fashion, it will be accompanied by a Vary: *
or Vary: Accept-Language
header. Otherwise it's really just informational. (It never catched on to be widely used all by itself.)
精彩评论