accessing value of a constant from another page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freefony
    New Member
    • Nov 2008
    • 59

    accessing value of a constant from another page

    hi am going thru a joomla script and they are accessing a constant without re-defining it or including the file where it was originally define. the first line of codes on the script is
    Code:
    defined('_JEXEC') or die('restricted access');
    how is this possible
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    this line simply checks, whether the constant _JEXEC has been already defined or not. besides that, the line does not access the constant itself, only the name is passed.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      The purpose of this is to prevent direct access to the file. If you access the file directly (e.g. http://your.tld/include/protected.php), the constant _JEXEC isn't defined. However, if this file is included via a PHP file where that constant has been defined, it will load appropriately.

      Code:
      <?php
      define( '_JEXEC', 1 );
      
      // access-protected file
      include 'included/protected.php';

      Comment

      Working...