Rich Darvins Rich Darvins -5 years ago 118
PHP Question

How to tell if a file has already been required?

I've created a php global file (globs.php), and have required it in all of my pages.
However, some pages are now including other pages, and I'm getting an error when it tries to require globs.php again.

How can I tell if a file has been required? That way, I could do if !required('globs.php') require('globs.php').

Answer Source

You can also make your own require_file function:

function require_file($file_path){
    static $required_files=array();
        require $file_path;
        return true;
    return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download