简体   繁体   English

以递归方式将文件包含在所有php文件中

[英]Include a file to all php files recursively

I have this file that I want to run first before each PHP file. 我有这个文件,我想先在每个PHP文件之前运行。 How can I achieve that? 我怎样才能做到这一点? Now, I only use a classic php way. 现在,我只使用经典的PHP方式。

run_me_first.php

and I want to tinclude it in my all of my PHP file. 我希望在我的所有PHP文件中包含它。 Besides putting it manually, is there a way not doing it manually? 除了手动放置之外,有没有办法不手动操作?

This could be achieved by using a require or include function to include the file in each of your php files. 这可以通过使用require或include函数将文件包含在每个php文件中来实现。 You haven't provided a great deal of information, so any response I can offer will be broad and may not pay to your particular needs. 您没有提供大量信息,因此我可以提供的任何回复都很广泛,可能无法满足您的特定需求。

I think You have an header file. 我想你有一个头文件。 If You dont't have then You create an header.php . 如果你没有那么你创建一个header.php Then include all Your files (.php , .js) which You want to include in all Your php files. 然后包括您想要包含在所有PHP文件中的所有文件(.php,.js) Then You need to only include the header.php in the above of all Your php file. 然后你需要在你的所有php文件的上面只包含header.php

Then this header.php will automatically include all Your required files. 然后这个header.php将自动包含所有您需要的文件。 This will reduce time and also will reduce the probability of error. 这将减少时间并且还将减少错误的可能性。 This is the process which I used to follow in all of my project. 这是我过去在我的所有项目中遵循的过程。

Please try it with an .htaccess file: 请使用.htaccess文件尝试:

php_value auto_prepend_file "/path/to/file/run_me_first.php"

If it's a free FTP, they might have some restrictions on what settings you can alter. 如果它是免费的FTP,他们可能会对您可以更改的设置有一些限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM