We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12379
    • 460 Posts
    I’m using this snippet of code to prevent manager pages from being accessed from the frontend:
    <?php
    if (realpath(__FILE__) == realpath($_SERVER['file_to_be_protected.php'])) {
    exit('This file can not be accessed directly.');
    }
    if(IN_MANAGER_MODE!="true") die("Please use the MODx Manager.");
    ?>
    

    While this works in one installation, it gives the following error in System Events:

    Undefined index: file_to_be_protected.php
    (Running: PHP Version 5.2.8)

    In another installation when I insert it at the top of the page I get the following error on the page itself:

    Error while inserting event log into database.
    (Running: PHP Version 5.2.6)

    ...but no errors in the System Events log!



      Mostly harmless.
      • 12379
      • 460 Posts
      This is an actual file on the server running within the modules section.
        Mostly harmless.
        • 10449
        • 956 Posts
        Try changing the first line to:

        if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) {


        Insert that in the file (script) you want to include, not in the modx module textarea.
          • 12379
          • 460 Posts
          That’s it - thanks! embarrassed
            Mostly harmless.