File Include Check
By: Daniel

Does your website have several files that are included? Do you not want to have them output anything if they are addressed directly? Here is a very simple script to do that:

<?php
function amIincluded() {
  $requestedURL = parse_url($_SERVER['REQUEST_URI']);
  if(basename($requestedURL['path']) != basename(__FILE__))
   return true;
  return false;
}
?>

This amIincluded function gets the address of the page in your browser. Then it parses that into its parts and gets the filename. If that filename is the same as the filename of the file, it returns true otherwise it returns false.

A sample usage of this is:

<?php
if(amIincluded()) {
echo 'Included';
} else {
echo 'Not Included';
}
?>
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

2 Responses to “File Include Check”

  1. Level-of-Detail Says:

    That is somewhat useless since it won’t be parsed if it is not included.

  2. Level-of-Detail Says:

    Nevermind what I said before it is late, I contracted some sort of temporary retardation due to lack of sleep.

Leave a Reply

geovisitors