We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17036
    • 2 Posts
    Hello,

    As this is my first post i want to thank the community of ModX for this excellent CMS! however i have a problem.

    I’m trying to return a header("HTTP/1.0 403 Forbidden"); status code for some documents. I have folder aliases turned on and some folders should look like it is a real directory which cannot be accessed directly. If googlebot sees an url like test.com/news/item1.html it probably tries to access the news folder too. I don’t want that in my scenario.

    I tied making a snippet with this content:
    <?php
    header("HTTP/1.0 403 Forbidden");
    ?>

    and a variations like these:
    <?php
    header("Status: 403 Forbidden");
    ?>

    <?php
    header("HTTP/1.0 403 Forbidden");
    header("Status: 403 Forbidden");
    ?>

    I called the snippets from within the documents content and nothing happened. A header("redirect:www.test.com"); did work. I dont understand what is the problem with the 403 header. Can give anyone advice?
      • 22303 MODX Staff
      • 10,725 Posts
      403; why not send 404?? Try using $modx->sendErrorPage() for a 404 and $modx->sendUnauthorizedPage() for a 401 or you can call $modx->sendForward() to send the request to another pages content silently and set the header to 403 if you want.
        • 31337
        • 258 Posts
        401 means "Show me your credentials"
        403 means "Your credentials suck -- go away"

        Just adding that as an FYI on why he might want one and not the other

        oh btw, the proper way to send a header is:
        header("HTTP/1.1 401 Authorization Required");
        or
        header("HTTP/1.1 403 Forbidden");
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: vbrilon at Dec 08, 2006, 11:28 PM

          oh btw, the proper way to send a header is:
          header("HTTP/1.1 401 Authorization Required");
          or
          header("HTTP/1.1 403 Forbidden");
          FYI, the sendForward() method I mentioned, which is now available in 0.9.5, allows you to pass a second parameter indicating the value of a header call exactly as described by Victor. The sendUnauthorizedPage() sets the proper 401 header for you (404 for sendErrorPage()).