Jonathan Pellerin
Jonathan Pellerin

Reputation: 432

Overriding include functions in php?

Is there a way to override include functions (include, include_once, require, require_once, etc) in PHP? I want to be able to do some code before including a file in the script. I'm working on a system that will allow plugins to be installed, but I don't want a plugin opening one or more of the core files and viewing their content. So I would like to be able to block these files when using include functions (especially file_get_contents()) but I obviously can't simply disable these functions.

I have thought about just changing the owner/access rights to these files, but apache needs read/execute rights to these so automatically, we can get their content by using file_get_contents();

Is there a way I can do that? Or am I viewing this the wrong way??

Thank you very much.

Upvotes: 1

Views: 1898

Answers (1)

George Cummins
George Cummins

Reputation: 28936

If it is worth spending the processing power, you can use fopen or file_get_contents to read the PHP files as text and search for the forbidden functions, then include or ignore them based on the result.

Upvotes: 1

Related Questions