We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42924
    • 7 Posts
    I have a snippet that runs on a page to check user input from a form post and want to return a 403 if naughty input is detected.

    I have tried $modx->sendUnauthorizedPage(); but that returns a 401 response code.

    How can I return a 403 response code from a snippet?

    revo 2.2.6 [ed. note: mikegrace last edited this post 11 years ago.]
    • I don't know of a MODX-specific way to do this. I would just use the PHP header() function:
      header("HTTP/1.0 404 Forbidden");
      
        • 6629
        • 60 Posts
        Quote from: mikegrace at May 07, 2013, 01:52 PM
        How can I return a 403 response code from a snippet?

        modX.sendRedirect
          • 42924
          • 7 Posts
          Quote from: DasItsch at May 09, 2013, 06:54 AM
          Quote from: mikegrace at May 07, 2013, 01:52 PM
          How can I return a 403 response code from a snippet?

          modX.sendRedirect

          It doesn't look like using the modX.sendRedirect works to send a 403. I tried

          $modx->sendRedirect('/403.html',array('responseCode' => 'HTTP/1.1 403 Forbidden'));


          but it just returns 302.

          Using

          header("HTTP/1.0 404 Forbidden");


          I am able to get a 403 header response but it returns the page that was originally requested.
          • Oops, sorry for the typo - obviously I meant "403 Forbidden."

            I think the problem with using $modx->sendRedirect is that 403 isn't a redirect. It's a status code indicating that you don't have permission to access the resource.

            I think you can stop it from sending the page content if you just die() after sending the 403, but I haven't tried it.