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.

This entry was posted in Technology. Bookmark the permalink.

1 Response to Including vs. direct access

  1. Vaughn says:

    Keep it up man.,

Leave a Reply

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