Including vs. direct access

Note to self: you can tell whether a PHP script is being called from another script using include() or is being accessed directly using this simple function:

function is_included () {
  if (strpos('[Root]' . __FILE__, $_SERVER['PHP_SELF']) > 4) {
    return false;
  } else {
    return true;
  }
}

The function will return true if the script is being included by another script and false if the script is accessed directly.

1 thought on “Including vs. direct access

Leave a Reply

Your email address will not be published. Required fields are marked *