如何将PHP文件包含站点范围内使用的.htaccess或其他方法 [英] How To Include a PHP File Site-wide Using .HTACCESS or other methods

查看:171
本文介绍了如何将PHP文件包含站点范围内使用的.htaccess或其他方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括在每一页我的网络服务器是一个的.php或.html文件

在我的PHP文件 googleanayltics.php

我想知道:

A)我如何加入这一权利之前,< /头> 标记
B)如何添加对对在<身体GT; 标记

我想知道这两种方法的灵活性

我想的.htaccess可以很容易地做到这一点,如果你知道如何,或者如果你知道任何简单的方法的话,请做分享。

P.S。我不想手动去,并输入每个文件code,这就是为什么我问这个问题(为节省时间)

解决方案
  

编辑:只是现在我明白你的真正想要的(被隐藏由于格式化)。   虽然有可能,这将是一个非常笨拙的事情,真是不值得。   看我其他答案的方式来做到这一点。


有两种 的php.ini 设置,您可能会感兴趣的:

AUTO_ prepend_file auto_append_file所

他们可以通过htaccess的改变(见对方的回答)。

注意的:

  • 这些将被列入前或整个PHP脚本之后;但不是在输出的特定部分。

  • 他们只会影响通过PHP,这意味着HTML文件不包括在内,除非你的服务器设置为通过PHP通过HTML文件处理的文件。这可以通过添加下面一行到你的.htaccess来完成:

     将AddType应用/ X的httpd  -  PHP的。html的热媒
     

  • 汽车prepending生成输出文件是一个危险的事情,因为它会影响(破)脚本设置页眉或使用会话。

I want to include my PHP file googleanayltics.php on every page on my webserver that is a .php or .html document

I would like to know:

A) How do I add this right BEFORE the </head> tag
B) How do I add right right AFTER the <body> tag

I'd like to know both methods for flexibility

I think .HTACCESS could accomplish this easily, and if you know how, or if you know of any easier method then please do share.

P.S. I do not want to manually go in and enter a code on every file, that is why I am asking this question (for time saving)

解决方案

EDIT: Only now I see what you actually wanted (was hidden due to formatting). Although possible, that would be a very clumsy thing to do, and really not worth the effort. See my other answer for a way to do that.


There are two php.ini settings you might be interested in:

auto_prepend_file and auto_append_file

They can be changed via .htaccess (see the other answer).

NOTES:

  • These will be included before or after the whole PHP script; but not in specific sections of the output.

  • They will only affect files handled that go through PHP, which means HTML files are not included, unless your server is set up to pass HTML files through PHP. This can be done by adding the following line to your .htaccess:

    AddType application/x-httpd-php .html .htm
    

  • Auto prepending a file that generates output is a dangerous thing to do, because it will affect (break) scripts that set headers or use sessions.

这篇关于如何将PHP文件包含站点范围内使用的.htaccess或其他方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆