Want to stop a PHP file from being opened directly instead of through another? This can be particularly useful for PHP files that depend on another or just to keep security tight.
So how do this work? PHP allows you to define something and you can then check to see if it is defined somewhere else in the code.
Should be one of the very first, if not the first, lines in your main file.
// Let's define it!
define('ABC');
Place this at the top of every other page that you want to be forced through the main one.
if(!defined('ABC'))
die();
Although it seems so simple, you’d be surprised at how many scripts aren’t protected. WordPress, for instance, doesn’t which allows you to look at theme files amongst other things.
Comments
No responses have been made so far. Add your comments.