it works by making sure the php script does not start until the environment is running. Thus, the user cannot execute the script without going to the corresponding page.
Here is an example. We have 2 files:
index.php
<?php define("_MY_FRAMEWORK", 1); echo 'started'; require('script.php'); ?>
and script.php
<?php if (!defined("_MY_FRAMEWORK")) exit; echo "my script"; ?>
If you run script.php directly, nothing will happen because _MY_FRAMEWORK is undefined. he will come out.
However, if you run index.php, which includes script.php, the script will continue because you first defined _MY_FRAMEWORK . You will get the full output: started , and then my script .
@Gumbo makes a good point: if you have not seen define before, it defines a constant that cannot be changed. User contributions to PHP documentation can be helpful in understanding how this works.
source share