PHP在单个文件中执行include语句但会影响许多文件

Does someone know how to make a script that is always included in a php file.
For Example, I have an index.php, I wanted to include script.php by doing include 'script.php'; Again, I have a login.php and I wanted to include script.php by doing include 'script.php';

I think this is very tiring to do and I think this is not a good idea because it is very repetitive. Is there a way where I can include script.php without doing include in each of the file? Like I should do that in a single file then everything would be affected.

Any idea would be greatly appreciated and rewarded. Thanks! :)

The only way to literally do what you are asking that I know of is through a config option:

auto_prepend_file

If your PHP code is OO, you could look into cleaner solutions such as autoload. Which I would recommend over the auto_prepend_file. A step down from that would be just use 1 file that you do include from all of your other files maybe named init.php, but then anything else you need included to all of your files you add the include to init.php. Not the cleanest solution, but easy and fast to implement and doesn't involve any config changes.

You could use auto_prepend_file.

The PHP configuration directive auto_prepend_file does this, but I think it's better to use an autoload function instead. That way, if a class you use is not defined, its source file is automatically located and included. Of course, you have to do a little extra work to structure your filesystem and write the code to locate those files. There are lots of questions on SO that cover autoloading strategies.