duffs Posted February 13, 2006 Posted February 13, 2006 Hi, I'm trying to setup a custom error page for a 401 error. Here's my .htaccess: ErrorDocument 404 /notfound.php ErrorDocument 401 /unauthorized.php The problem is, it doesn't seem to parse php correctly for a 401 error. Note my 404 works fine; the page is displayed properly. However, when my 401 page is displayed, it looks like it's totally ignoring the php. I see the html of the page, so it's finding the page ok, it just isn't parsing the php. Is there some reason why a php page can't be used for a custom 401? Or is there another step I need to do to have the server parse the php properly? Thanks. Quote
TCH-Don Posted February 13, 2006 Posted February 13, 2006 I will assume there are no errors in the php? I can't see why it will not work. Quote
duffs Posted February 13, 2006 Author Posted February 13, 2006 Correct, if I just go to the page straight, it works fine. In fact, the page is an exact duplicate of my 404 page, with slightly different text. The 404 is correctly served, but the 401 is not. It looks like for some reason it does not parse the php properly in the 401 error page, even though it does in the 404. Is there something about the nature of a 401 that causes the php not to be parsed? Perhaps this is an Apache bug? Quote
TCH-Bruce Posted February 13, 2006 Posted February 13, 2006 Easy way to tell is set your 401 error to display your 404 page. Quote
duffs Posted February 14, 2006 Author Posted February 14, 2006 Hi, Tried that. Same result; showed the html of the page only and ignored the php. Hmm...anyone know any workarounds? Quote
duffs Posted February 15, 2006 Author Posted February 15, 2006 Well....looks like I misdiagnosed the problem. I was using php to set the stylesheet based on the browser. When the stylesheet wasn't being invoked properly, I incorrectly assumed the php wasn't working. But really the issue is since I got the 401 by trying to access a subfolder, it looks like I was no longer at the root level, even though my 401 page was located there. Clear as mud, I know. Specifically, a simplified version of my page had this code: <?php echo '<link rel="stylesheet" href="styles/sdi3column_allbrowsers.css" type="text/css">'; ?> Note that "styles/sdi3column_allbrowsers.css" is assuming I'm at the root level. (My 401 page IS at the root level). If I got the page by calling it, http://www.silverleafdesign.com/unauthorizedtest.php, the page rendered fine. However, if I got the page by going to www.silverleafdesign.com, clicking on Client Login, and then hitting Cancel, the page did not find the stylesheet. However, when I changed the path of the stylesheet in the 401 page to "/styles/sdi3column_allbrowsers.css" (added / to the front), then the page rendered correctly when I got there by trying to log in. Do you know why this would be the case? Logically, since the 401 page is at the root level, I would think that "styles/sdi3column_allbrowsers.css" would work correctly, but it didn't until I add the /. Why would this be? Thanks, Susie Quote
TCH-Bruce Posted February 15, 2006 Posted February 15, 2006 When I run into problems like that I code it with a full path to the CSS file. ><?php echo '<link rel="stylesheet" href="http://your-site.ext/styles/sdi3column_allbrowsers.css" type="text/css">'; ?> Then the server doesn't have to guess where you are trying to point too. Quote
TCH-JimE Posted February 15, 2006 Posted February 15, 2006 Hello, It has all to do with paths. Rather then try and explain and re-write the wheel so to speak, have a look here: http://www.phphelp.com/strands/article/000012.php Its rather useful! I often use ><?php include $_SERVER['DOCUMENT_ROOT']."/inc/navmenu.php"; ?> When hard coding a line in but Bruce's one is just as good Jimuni Quote
duffs Posted February 15, 2006 Author Posted February 15, 2006 Hi, Thanks for the suggestions. The article you mentioned, Jimuni, is referring to using includes. In my case, I'm not using an include, I'm calling a 401 page that is located in the root. Nevertheless, the article states that, for includes, the path is relative to the calling page. If that logic carried over to my 401 page, it should work. Since the 401 page is at the root level, calling a stylesheet from within that page where the path is relative to the root level should work fine. That doesn't explain to me why the path in the 401 page is NOT relative to the location of that page; it is relative to the subfolder I tried to access when the 401 was called. I understand the workarounds to make the path absolute, but I'm still wondering why it behaves this way in the first place. Thanks. Quote
TCH-JimE Posted February 15, 2006 Posted February 15, 2006 (edited) Hello, Yes the page is about includes, but the paths for php remain the same, hope it was not too confusing! >"/styles/sdi3column_allbrowsers.css" This is an absolute path, so no matter where you place it, it will always pull that page. If however, you are creating the 401 from a sub folder, e.g. www.domain.com/subfolder/401.php Even though your pulling the file from the root, the relative path is still www.domain.com/subdfolder/401.php Hence the original >styles/sdi3column_allbrowsers.css would not have worked as you it would be looking to pull: www.domain.com/subdfolder/styles/sdi3column_allbrowsers.css and you would have needed to have put >../styles/sdi3column_allbrowsers.css for the page to work correctley I think anyway! Jimuni Edited February 15, 2006 by Jimuni Quote
duffs Posted February 15, 2006 Author Posted February 15, 2006 My 401 page is NOT in a subfolder, it's at the root level. That's my point. www.domain.com/401.php It works fine if you call it straight: www.domain.com/401.php It doesn't work if it is invoked by trying to access a subfolder that you don't have access to. Quote
TCH-JimE Posted February 15, 2006 Posted February 15, 2006 (edited) Hello, Whilst the 401 is at root level, the error page is being called from a subfolder, e.g: http://www.silverleafdesign.com/clientarea/client.php E.g normal error: http://www.silverleafdesign.com/401.php Subfolder error (ok not correct url but you see what i mean) http://www.silverleafdesign.com/401.php hence whilst both pages pull and show the same 401 page, the actually path for that page is different because of where its being viewed from, hence the above notes in my previous post. Jimuni Edited February 15, 2006 by Jimuni Quote
duffs Posted February 15, 2006 Author Posted February 15, 2006 Then I'm not quite understanding how a 401 works. Even though it is being called from the subfolder, the page still lives in the root, correct? Isn't the root page being served? Quote
TCH-JimE Posted February 16, 2006 Posted February 16, 2006 Hello, Correct, its the root page that is being serverd, but because it can be served anywhere, the path can change. Jimuni Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.