Adding an http header site wide in php

醉酒当歌 提交于 2020-01-05 07:39:08

问题


I'm maintaining a web site for a non-profit organisation. I'm not the one who designed this web site, and I don't know the person who did it.

That said, I have an issue with IE9. I will eventually try to correct it, but meanhile just adding the X-UA-Compatible header so IE9 turns to IE8 mode would work just fine.

In an asp.net web site, I would add it in the web.config with the <customHeaders> element (with IIS7).

Is there's a way to send this header for all file in a php web site, without editing all files?


回答1:


Apache MOD_HEADERS, add the following to your root .htaccess file

<FilesMatch "\.(php|cgi|pl|htm)$">
    Header set X-UA-Compatible IE=EmulateIE8
</FilesMatch>

This will set that header in the http header of all php, html, perl and cgi files, but I have had very bad experiences with the x-ua header, and found that it doesn't always work.




回答2:


auto_prepend_file and header(), or configure it in your web server with e.g. Header.




回答3:


If you're using some kind of templating engine, you could just add <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /> to the HEAD section of your template(s).

Otherwise, if you're including a single PHP file everywhere, you could add a header() call there (as long as it's before you output any content).



来源:https://stackoverflow.com/questions/6933509/adding-an-http-header-site-wide-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!