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 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 51 Votes | Average: 5 out of 5 (1 votes, average: 5 out of 5)
Loading ... Loading ...
del.icio.us:File Include Check digg:File Include Check spurl:File Include Check wists:File Include Check simpy:File Include Check newsvine:File Include Check blinklist:File Include Check furl:File Include Check reddit:File Include Check fark:File Include Check blogmarks:File Include Check Y!:File Include Check smarking:File Include Check magnolia:File Include Check segnalo:File Include Check

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

eXTReMe Tracker
geovisitors