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

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

问题描述

我想将我的 PHP 文件 googleanayltics.php 包含在我的网络服务器上的每个页面上,即 .php 或 .html 文档

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

我想知道:

A) 我如何在 </head> 标签之前添加它
B) 如何在 <body> 标签

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

我认为 .HTACCESS 可以轻松完成此操作,如果您知道如何操作,或者您知道任何更简单的方法,请分享.

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)

推荐答案

现在我才看到你真正想要的(由于格式化而被隐藏).虽然有可能,但这将是一件非常笨拙的事情,而且真的不值得付出努力.请参阅我的其他答案以了解如何做到这一点.

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.

<小时>

有两个 php.ini 设置您可能感兴趣:


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

auto_prepend_fileauto_append_file

它们可以通过 .htaccess 更改(请参阅其他答案).

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

注意事项:

  • 这些将包含在整个 PHP 脚本之前或之后;但不在输出的特定部分.

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

它们只会影响通过 PHP 处理的文件,这意味着不包括 HTML 文件,除非您的服务器设置为通过 PHP 传递 HTML 文件.这可以通过将以下行添加到您的 .htaccess 中来完成:

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.

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

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