Jump to content

Please help me to convert this code to PHP!


ravira

Recommended Posts

Hello!

 

I want to set the MIME type according to my visitor's handheld device'. Please anyone could help me to convert this code to PHP. (I guess, this is in ASP):

 

<%

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");

%>

 

 

My coding level is below intermediate above beginner. But, I dont know how code to get handheld device's type, and other details. If you can advice any tutor/help/reference (links/resource), please let me know.

 

 

Thanks in advance

 

$accept = $_SERVER["HTTP_ACCEPT"];
$user_agent = $_SERVER["HTTP_USER_AGENT"];
$accept_charset = $_SERVER["HTTP_ACCEPT_CHARSET"];
$accept_language = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
$x_wap_profile = $_SERVER["HTTP_X_WAP_PROFILE"];
$profile = $_SERVER["HTTP_PROFILE"];

 

This should be all you need.

Thanks kratsg and Mchl!

 

I have tried but failed to further build up. particularly, I don't know how use $x_wap_profile. and how send headers (application/vnd.wap.xhtml+xml, application/xhtml+xml, ...) to handheld devices?

 

I'm totally new to code for handheld devices. and I have not had an experience in processing the $_SERVER["HTTP_"s, and sending file headers.

 

Please help me with an example. or convert this code to PHP:

 

[pre]<%

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");

%>[/pre]

 

 

Thanks again.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.