{"id":477,"date":"2008-06-20T17:30:45","date_gmt":"2008-06-20T23:30:45","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/archives\/000477"},"modified":"2008-06-20T17:31:18","modified_gmt":"2008-06-20T23:31:18","slug":"setting-headers-in-a-php-include-directive","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/477","title":{"rendered":"Setting headers in a PHP include directive"},"content":{"rendered":"<p>I am currently working on a project that uses a PHP CMS for the bulk of the site.  However, it pulls some content from a page generated by JSTL on a tomcat.  I was using the fmt tag to do some pretty printing of numbers, and it looked fine when I viewed the content as served by tomcat.  However, none of the formatting was carrying through when the PHP page included the jsp.  Why?  It appears that the <a href=\"http:\/\/mail-archives.apache.org\/mod_mbox\/jakarta-taglibs-user\/200410.mbox\/%3C200410141245.55548.f.tordini@kataweb.it%3E\">fmt tag needs a locale<\/a>. I confirmed that with <a href=\"\/wordpress\/archives\/000261\">wget<\/a>.<\/p>\n<p>Now, how to set the header with the PHP include.  The <a href=\"http:\/\/www.php.net\/manual\/en\/function.include.php\">include man page<\/a> was no help, and <a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/mod_rewrite.html\">mod_rewrite won&#8217;t let you modify headers<\/a>, as far as I can tell.  Once the request arrived to tomcat, that was too late.<\/p>\n<p>Some digging around in the PHP documentation on <a href=\"http:\/\/www.php.net\/manual\/en\/function.fopen.php\">fopen<\/a> turned up this gem:<\/p>\n<blockquote><p><a href=\"http:\/\/www.php.net\/manual\/en\/wrappers.http.php\">Custom headers may be sent with an HTTP request prior to    version 5 by taking advantage of a side-effect in the    handling of the <em>user_agent<\/em> INI setting.    Set <em>user_agent<\/em> to any valid string    (such as the default <em>PHP\/version<\/em> setting)    followed by a carriage-return\/line-feed pair and any    additional headers.    This method works in PHP 4 and all later versions.<\/a><\/p><\/blockquote>\n<p>Click through for a code example.  The aforementioned documentation talks about custom headers, but it worked for sending the Accept-Language header that the fmt tags needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am currently working on a project that uses a PHP CMS for the bulk of the site. However, it pulls some content from a page generated by JSTL on [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,5,17],"tags":[],"class_list":["post-477","post","type-post","status-publish","format-standard","hentry","category-http","category-java","category-php"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=477"}],"version-history":[{"count":0,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/477\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}