Error Document Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Error Document Question

Post by AGISB »

Here is what I want to achive.

I got help pages in a folder. I handle the 404 errors with a .htaccess Error Document directive. If a user clicks on a help page link the appropriate help link opens in its own window. If it is not there the error php page is called.

I now want to get a notice what page is missing by e.g. an email so I can fix the problem.

As each help file opens in a namned window I like to know if there is a way in php to read the window name? Or any other means to achive this?

I know it is possible in Javascript but a php solution I would prefer.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

The window name...no, as PHP is not client side. The url of the page yes.

Code: Select all

print_r($_SERVER);
And take you pick of variables that will tell you what page was called. And then use the mail() function to send an email or sms message for even faster notification :P
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

$_SERVER does not work as it gives me the page who called the missing page but it might display many different help page links on the same referer page.

Guess I got to resort to javascript.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

you could do it in htaccess

instead of using the error docs directive, you coula kinda make your own

this will rewrite any file that doesnt exist to error-404.php
because this is an internal rewrite, php's $_SERVER array will now have the proper info in it.

Code: Select all

RewriteEngine On
RewriteCond    %{REQUEST_FILENAME}  !-f
RewriteRule .* error-404.php їL]
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Hey guys,

I moved this topic as I didn't feel it really fit in with this portion of the board.

Cheers,
BDKR
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

I think this goes about Theory and Design but what do I know?

Anyway here is the solution for anyone who looks this up and needs a solution:

$_SERVER['REDIRECT_URL'] or $_SERVER['REQUEST_URI'] will give you the Pagename that is missing

$_SERVER['REDIRECT_ERROR_NOTES'] will give you the error message

However there is a very important part that need to be paid attention to.

in .htaccess the ErrorDocument directive cannot have the full URL but just the path with a / in front

e.g.

ErrorDocument 404 /404/error.php

if you use

ErrorDocument 404 http://www.justasample.com/404/error.php

those variables above are not correctly set as the correct info is lost in an external redirect.
Post Reply