[php/htacc.] getting referer of page that errors

software development

#1

hi, i need some serious help! i have a script i got from hotscripts.com that helps you control errordocument handling…

the script works pretty well, execpt that i NEVER know what page the person who fires of my errordocument handler is coming from.

for instance, a person is at my site on the following page:

toocrooked.com/index.html

they click some link that leads to a 404, and my error handler picks it up. the error handler emails me info about the error, for instance the type (404), the requested link (toocrooked.com/nonexistant.html) and the referring page (toocrooked.com/index.html)

…however, i NEVER have EVER never gotten the referring page. i have asked for help about this before on other places, and stupid [expletive deleted]'s always say “oh, someone is blocking the referrer. oh you didnt spell referrer right”, and etc. but they are just plain stupid. so thats why im here - i need a real, correct answer.

anyway, heres how the code looks:

.HTACCESS

[quote]order allow,deny
deny from 24.203.221.239
deny from 38.99.203.110
allow from all
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
ErrorDocument 400 /errorpage.php
#ErrorDocument 401 /errorpage.php
ErrorDocument 403 /errorpage.php
ErrorDocument 404 /errorpage.php
ErrorDocument 500 /errorpage.php[/quote]

errorpage.php:

[quote] <?php
/*
Dynamic Error Pages v2.01

Copyright © 2005 Sabre Web Design (www.sabrewebdesign.com)
All rights reserved.

If you like this script, we would appreciate a link back to Sabre Web Design (www.sabrewebdesign.com).

HOW TO INSTALL THE SCRIPT:

  • Copy and paste this whole script into your page where you would like your error to be displayed.
  • Change the "error@example.com" e-mail below to your e-mail address.
  • Add the following lines to your .htaccess file (change the location of your error page, if needed):
    ErrorDocument 400 /errorpage.php
    ErrorDocument 401 /errorpage.php
    ErrorDocument 403 /errorpage.php
    ErrorDocument 404 /errorpage.php
    ErrorDocument 500 /errorpage.php
  • And it’s as simple as that!

*/

// Setup
$email = ‘webmaster@toocrooked.com’; //Change to your email address

// Get Variables
$error = $_SERVER[‘REDIRECT_STATUS’];
$referring_url = $_SERVER[‘HTTP_REFERER’];
$requested_url = $_SERVER[‘REQUEST_URI’];
$referring_ip = $_SERVER[‘REMOTE_ADDR’];
$server_name = $_SERVER[‘SERVER_NAME’];

// Different error messages to display
switch ($error) {

Error 400 - Bad Request

case 400:
$errorname = ‘Error 400 - Bad Request’;
$errordesc = '

Bad Request

Error 400

The URL that you requested, was a bad request.

If this problem persists please report it by sending an e-mail to '.$email.', mentioning the error message received and the page you were trying to reach. We are sorry for any inconvenience caused and we will do all we can to fix the error as soon as possible.

'; break;

Error 401 - Authorization Required

case 401:
$errorname = ‘Error 401 - Authorization Required’;
$errordesc = '

Authorization Required

Error 401

The URL that you requested, requires pre-authorization to access.

If this problem persists please report it by sending an e-mail to '.$email.', mentioning the error message received and the page you were trying to reach. We are sorry for any inconvenience caused and we will do all we can to fix the error as soon as possible.

'; break;

Error 403 - Access Forbidden

case 403:
$errorname = ‘Error 403 - Access Forbidden’;
$errordesc = '

Access Forbidden

Error 403

Access to the URL that you requested, is forbidden.

If this problem persists please report it by sending an e-mail to '.$email.', mentioning the error message received and the page you were trying to reach. We are sorry for any inconvenience caused and we will do all we can to fix the error as soon as possible.

'; break;

Error 404 - Page Not Found

case 404:
$errorname = ‘Error 404 - Page Not Found’;
$errordesc = '

File Not Found

Error 404

We are sorry but the page you are looking for cannot be found.

If this problem persists please report it by sending an e-mail to '.$email.', mentioning the error message received and the page you were trying to reach. We are sorry for any inconvenience caused and we will do all we can to fix the error as soon as possible.

'; break;

Error 500 - Server Configuration Error

case 500:
$errorname = ‘Error 500 - Server Configuration Error’;
$errordesc = '

Server
Configuration Error

Error 500

The URL that you requested, resulted in a server configuration error. It is possible that the condition causing the problem will be gone by the time you finish reading this.

If this problem persists please report it by sending an e-mail to '.$email.', mentioning the error message received and the page you were trying to reach. We are sorry for any inconvenience caused and we will do all we can to fix the error as soon as possible.

'; break;

Unknown error

default:
$errorname = ‘Unknown Error’;
$errordesc = '

Unknown Error

The URL that you requested, resulted in an unknown error. It is possible that the condition causing the problem will be gone by the time you finish reading this.

If this problem persists please report it by sending an e-mail to '.$email.', mentioning the error message received and the page you were trying to reach. We are sorry for any inconvenience caused and we will do all we can to fix the error as soon as possible.

';

}

// Display selected error message
echo($errordesc);
if (!$referring_url == ‘’) {
echo ‘

<< Go back to previous page.

’;
} else {
echo ‘

<< Go back to previous page.

’;

echo ‘

Dynamic Error Pages from Sabre Web Design.

’;

// E-mail section. Delete if you do not want to be sent e-mail notifications of errors.
$datetime = date(“l dS of F Y - H:i:s”);
$message .= ‘The following error has been received on ‘.$datetime.’’;
$message .= ’

‘.$errorname.’’;
$message .= ‘
Requested URL: ‘.$server_name.$requested_url.’’;
$message .= ‘
Referring URL: ‘.$referring_url.’’;
$message .= ’

IP Address: '.$referring_ip;
$to = “$email”;
$subject = “$errorname”;
$headers = “From: $email\r\n”;
$headers .= “Content-type: text/html\r\n”;
mail($to,$subject,$message,$headers);
}
// End of e-mail section.
?>
[/quote]

again, i NEVER get a referer! the code is perfectly correct!! why wont the .HTACCESS file pass the god forsaken referring URL?

better yet, how can i get the HTACCESS to pass a GET variable with the referring URL in it, for instance, instead of calling errorpage.php, how can i get it to call:

errorpage.php?ref=%{REFERER} (or something like that)


#2

Try this:
if (!$referring_url == ‘’) {
echo ‘

<< Go back to previous page.

’;
}
Double check the value if (!$referring_url == ‘’) Make sure you have two single quote and not a single double quote. I beleive its right, but its good to verify.
Silk

My website


#3

sh[color=#000000]i[/color]t… looks like i wont get my answer here :frowning:

like i said, the code works. the problem is that i simply am not getting a referrer passed to my PHP page for one reason or another. it gets stripped at some point. i need some insight as to why.

sh[color=#000000]i[/color]t!!


#4

Sorry, I’m just a dumb sh1t who forges most referrers, and won’t take the time to seriously consider a post by someone who insults in advance. H3ll yes!

tor.eff.org


#5

The logic in the code says only send an email when there is no referring URL - so you are only being notified when the HTTP_REFERER is missing or empty. If you want to be emailed under all circumstances then change:

if (!$referring_url == ‘’) {
echo ‘

<< Go back to previous page.

’;
} else {
echo ‘

<< Go back to previous page.

’;

to

if (!$referring_url == ‘’) {
echo ‘

<< Go back to previous page.

’;
} else {
echo ‘

<< Go back to previous page.

’;
}

and remove the final } after the line

mail($to,$subject,$message,$headers);


#6

nice catch!! looks like that was the solution! thanks so much… the guys who did this script are idiots, and so am i to have done so little to troubleshoot that!! now ill finally know what sites are linking to the wrong stuff on my webpage!!!

goes to show that it wasnt because referrer wasnt spelled wrong, or that it was being blocked… !!! :smiley: