php not executing on server; giving me a error 500

the php code I am using is giving a error 500

Page 1 of 1

2 Replies - 1213 Views - Last Post: 26 August 2009 - 04:44 PM Rate Topic: -----

#1 lilmike  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 01-February 09

php not executing on server; giving me a error 500

Posted 26 August 2009 - 03:16 PM

Hi all,
I found some php code on the internet that I figured would work just dandy for my error page needs.
Unfortunately, it's not working at all as well as I'd hoped.
Wwhen I navigate to the error page directly, it gives me a error 500, internal server error.
It also gives this same error when I navigate to error.php?error=404 or whatever.
I found this on google, and I can't see anything wrong with it.
<html>
<head>
<meta name="robots" content="noindex, nofollow">
<title>A website error has occurred</title>
</head>
<body>
<?php
/*
Dynamic Error Pages v1.02

Copyright (c) 2004 Sabre Web Design <http://www.sabrewebdesign.com/>
All rights reserved.

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

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Redistributions of this script is free for Non-Commercial use ONLY!
* Neither the name of Sabre Web Design nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

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 /errorpages/errorpage.php?error=400
ErrorDocument 401 /errorpages/errorpage.php?error=401
ErrorDocument 403 /errorpages/errorpage.php?error=403
ErrorDocument 404 /errorpages/errorpage.php?error=404
ErrorDocument 500 /errorpages/errorpage.php?error=500
* And it's as simple as that!

*/

//Find error code
$error=$_GET['error'];

//E-mail to be used for errors (Change this to your email address)
$email = "xxx@xxx.xxx";

//Find reffering and requested URLs
$referring_url = $_SERVER['HTTP_REFERER'];
$requested_url = $_SERVER["REQUEST_URI"];

//Different error messages to display
switch ($_REQUEST['error']) {

//Error 400 - Bad Request
case 400:
$errorname = 'Error 400 - Bad Request';
$errordesc = '<h1>Error 400, Bad Request</h1><BR>
Error 400<BR>
<BR>
The URL that you requested was a bad request. <BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
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 = '<h1>Error 401, Authorization Required</h1><BR>
Error 401<BR>
<BR>
The URL that you requested may need a password to access.<BR>
<BR>
If you would like to pertain a password then please send an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
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.<BR>
</FONT>';
break;

//Error 403 - Access Forbidden
case 403:
$errorname = 'Error 403 - Access Forbidden';
$errordesc = '<h1>Error 403, Access Forbidden</h1><BR>
<BR>
Access to the URL that you requested is forbidden.<BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
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.<BR>
<br>
Also note that if the problem is not fixed in a reasonable amount of time, then you might not be allowed to access this 

directory.';
break;

//Error 404 - Page Not Found
case 404:
$errorname = 'Error 404 - Page Not Found';
$errordesc = '<h1>Error 404, Page Not Found<BR>
<BR>
We're sorry but the page you are looking for cannot be found.<BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
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.<BR>';
break;

//Error 500 - Server Configuration Error
case 500:
$errorname = 'Error 500 - Server Configuration Error';
$errordesc = '<h1>Error 500, Server Configuration Error<BR>
<BR>
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. <BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
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.<BR>';
break;

//Unknown error
default:
$errorname = 'Unknown Error';
$errordesc = '<h1>Unknown Error</h1><BR>
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. <BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
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.<BR>';

}

//Display selected error message
echo($errordesc);
if(referring_url != "") // for if the url was not there, maybe this doesn't work.
{
echo("<br>Click <a href="$referring_url">this link</a> to go back.</a>");
}


//E-mail error to your e-mail address (If you do not wish to receive emails delete the following paragraph)
$datetime = date("l dS of F Y H:i:s");
$message = "<i>The following error has been received on "."$datetime\n</i><br>\n<br>\n";
$message .= "<b><i>$errorname</i></b><br>\n";
$message .= "<i>Requested URL:</i> " . $requested_url . "\n<br><i>Referring URL:</i> " . $referring_url;
$message .= "\n<br><br><i>IP Address:</i> ".$_SERVER['REMOTE_ADDR'];

$to = "$email";
$subject = "Web Site Error";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to,$subject,$message,$headers);
//End of E-mail sender
?>
</body>
</html>


Thanks for any help you can provide,
-Lilmike.

Is This A Good Question/Topic? 0
  • +

Replies To: php not executing on server; giving me a error 500

#2 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: php not executing on server; giving me a error 500

Posted 26 August 2009 - 04:40 PM

View Postlilmike, on 26 Aug, 2009 - 04:16 PM, said:

When I navigate to the error page directly, it gives me a error 500, internal server error.

That's because there are parse errors in the script. On line 123, the apostrophe in "We're" needs to be escaped, as well as the double quotes for the href attribute on line 165. Also, the dollar sign is missing from "referring_url" on line 163. All this is easily detected when you run the script with error reporting set to E_ALL.
Was This Post Helpful? 0
  • +
  • -

#3 pyro78  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 26-August 09

Re: php not executing on server; giving me a error 500

Posted 26 August 2009 - 04:44 PM

This one has me a little stumped, i dont see an error in that code at all (doesnt mean there isnt one) did you edit your .htaccess file and add in this php file in the proper directory so that the .htaccess file is looking at it?

*edit* nice finds adahacker

This post has been edited by pyro78: 26 August 2009 - 04:45 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1