Hey, not exactly new to php, but not a seasoned veteran either. I have a page I manage, and I'm trying to get a nice error.php page to work which will print out a nice looking error based on the error code I am using.
I have a page on my site that I want to hide from non-admin users. Currently I do this by using a function(isUserAdmin) which runs in the header, which does a check against a DB. It grabs the user's id from the cookie, and then connects to mysql to see if the user is an admin. It then sets a php variable adminString to either True or false. This works and when I'm logged in I can see using FireFox Web Console, that as an admin user I get a 200, and as a non-admin user I get a 401 in the browser.
if($adminString == "False"){
http_response_code(401);
}
However, the page still displays. In my apache httpd.conf, I have:
#Define pages to load for certain http errors
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
That error.php page exists and seemingly works, b/c when I go to my site http://site.com/foo (which does not exist), I get my nice 404 page back in the browser.
How can I get php to trigger trigger the ErrorDocument through the web-server when I set the status code?