ravira Posted June 20, 2010 Share Posted June 20, 2010 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 Link to comment https://forums.phpfreaks.com/topic/205302-please-help-me-to-convert-this-code-to-php/ Share on other sites More sharing options...
kratsg Posted June 20, 2010 Share Posted June 20, 2010 $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. Link to comment https://forums.phpfreaks.com/topic/205302-please-help-me-to-convert-this-code-to-php/#findComment-1074548 Share on other sites More sharing options...
Mchl Posted June 20, 2010 Share Posted June 20, 2010 And also header to set up response headers. Link to comment https://forums.phpfreaks.com/topic/205302-please-help-me-to-convert-this-code-to-php/#findComment-1074568 Share on other sites More sharing options...
ravira Posted June 22, 2010 Author Share Posted June 22, 2010 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. Link to comment https://forums.phpfreaks.com/topic/205302-please-help-me-to-convert-this-code-to-php/#findComment-1075440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.