supertrucker Posted December 15, 2006 Share Posted December 15, 2006 I'm trying to plug a dynamic header into my PHP code, and all I currently have is this JSP code I found on theDevelopers Home site. I would really appreciate it if somebody could help me convert this code to PHP! I don't know JSP and could frankly, live quite peacefully, if I never have to learn another scripting language! For being a novice at this whole web authoring thing, I think I'm doing pretty well considering I now have a limited knowledge of, and history of, html+, xhtml, xhtml-mp, wml, wap, php... What I don't want to do IS LEARN ANOTHER!!! You can probably tell I'm a bit frustrated!I'm having fun! However, this code below here might as well be in hieroglyphics! All I need is a straight conversion in PHP. <%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");%> Thank you a thousand-fold in advance!Supertrucker Link to comment Share on other sites More sharing options...
MrAdam Posted December 17, 2006 Share Posted December 17, 2006 that's actually "ASP, JavaScript" and i don't think you can do that in PHP as far as i know. the closest you could get is dynamically writing out the header at the start of the page. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 18, 2006 Share Posted December 18, 2006 That code is looking in the accept header for mime types that the browser understands. First it looks for "application/vnd.wap.xhtml+xml", then "application/xhtml+xml". With PHP, you can access the accept header using $_SERVER['HTTP_ACCEPT']. The header function sends a header. So, the code above would look something like this in PHP: <?php$accept = $_SERVER['HTTP_ACCEPT'];if (strpos($accept, "application/vnd.wap.xhtml+xml") !== false) header('Content-type: application/vnd.wap.xhtml+xml');elseif (strpos($accept, "application/xhtml+xml") !== false) header('Content-type: application/xhtml+xml');else header('Content-type: text/html');?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now