|
|
|
| Как узнать в пхп принел ли браузер header?
хороше бы чтоб ктонибудь написал статью про заголовки.
Помогите разобраться.
Вот такая задача .
Choosing MIME Types Dynamically
Another option is to detect the MIME types that can be handled by a user agent and choose the MIME type dynamically. For example, if your server finds out that a certain user agent can handle the "application/vnd.wap.xhtml+xml" MIME type, then all your XHTML MP documents will be delivered as "application/vnd.wap.xhtml+xml" to this user agent.
To choose the MIME type dynamically, you need to write a few lines of code using a server-side scripting language (e.g. ASP, JSP, Perl, PHP). The pseudo-code is shown below:
1.
Obtain the accept header value of the HTTP request received. The accept header contains all MIME types that can be handled by the client user agent that sends the request.
2.
If the accept header value contains "application/vnd.wap.xhtml+xml", set the MIME type of the XHTML MP document to "application/vnd.wap.xhtml+xml".
Else if the accept header value contains "application/xhtml+xml", set the MIME type of the XHTML MP document to "application/xhtml+xml".
Else set the MIME type of the XHTML MP document to "text/html".
The following example demonstrates how to use JSP to write the code. If you use a server-side technology other than JSP, the code will be slightly different but the idea is the same.
<%
String acceptHeader = request.getHeader("accept");
if (acceptHeader.indexOf("application/vnd.wap.xhtml+xml") != -1)
response.setContentType("application/vnd.wap.xhtml+xml");
else if (acceptHeader.indexOf("application/xhtml+xml") != -1)
response.setContentType("application/xhtml+xml");
else
response.setContentType("text/html");
%> | |
|
|
|
|
|
|
|
для: xenux
(09.12.2006 в 00:54)
| | Вот вроде правильно !!!
<?php $accept = $_SERVER["HTTP_ACCEPT"];
$findme="application/vnd.wap.xhtml+xml";
$pos = strpos($accept, $findme);
if ($pos) header('Content-type: application/vnd.wap.xhtml+xml');
else
$findme="application/xhtml+xml";
$pos = strpos($accept, $findme);
if ($pos) header('Content-type: application/xhtml+xml');
else header('Content-type: application/xhtml+xml');
?>
|
| |
|
|
|