From Sagar Gulati, 4 Years ago, written in PHP.
Embed
  1. <?php
  2.  
  3. /**
  4.  * Returns true if current file is included
  5.  */
  6. function isIncluded() {
  7.     $f = get_included_files();
  8.     return $f[0] != __FILE__;
  9. }
  10.  
  11. if ( !isIncluded() ) {
  12.     // Do some stuff, eg: print some HTML
  13. } else {
  14.     // Do other stuff, 'cause you're included
  15. }
  16.  
  17. // You can also use (recommended)
  18. if ( __FILE__ != $_SERVER['SCRIPT_FILENAME'] ) {
  19.     // this file is being included
  20. }