i was recently browsing some php source code, particularly ones of forum software like phpbb and esotalk
I noticed one thing, most of them used a global variable at the start of their page as some sort of security like so:
if (!defined("IN_ESOTALK")) exit; //For esotalk
if (!defined("IN_PHPBB")) exit; //FOR phpbb
What sort of security is this? I don’t understand.
Could you explain to me what this prevents and how?
thanks,
Vidhu
it works by making sure the php script doesn’t run unless the framework has started up. This way the user can’t execute a script without going through the proper page.
Here’s an example. We have 2 files:
index.php
and script.php
If you run script.php directly, nothing will happen because
_MY_FRAMEWORKhas not been defined. it will exit.However, if you run index.php, which includes script.php, the script will continue because you did define
_MY_FRAMEWORKfirst. You will get the full output:startedfollowed bymy script.@Gumbo makes a good point: If you haven’t seen define before, it defines a constant that cannot be changed. The user contributions to the PHP documentation can be helpful to understand how it works.