We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

tylerhall on 04/11/07


Tagged

file include


Versions (?)


Who likes this?

6 people have marked this snippet as a favorite

basicmagic
bitcrumb
hudge
vali29
bioascii
jfherring


Test if a PHP File Is Being Included


Published in: PHP 


This tests to see if the current file is being included or run directly. It's useful to add to the top of your include files to stop malicious users from accessing them directly in the browser.

  1. if(__FILE__ == $_SERVER['SCRIPT_FILENAME'])
  2. die("This file cannot be executed directly");

Report this snippet 

You need to login to post a comment.