GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Aug-2003, 01:59
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about

Error Pages


NEW VERSION AVAILABLE: Error Handling with PHP

I am looking for a script that automatically sends an e-mail to an address I specify with details about: The URL the error occured at, the IP address of the user, and the time this occured.

I want to add it to my 404.php page that is on my server(no other pages!)

I can use a custom 404 page on my site, but I do not want to have to enter in any other information in my other pages.

I have checked on hostscripts.com and could not find any. Anyone have a suggestion? The only ones I have found make you edit more pages than just the 404 page. Ideas?
  #2  
Old 17-Aug-2003, 06:10
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Handling Error 404 - Email notification


I haven't done this before so you might have to give me some feedback in case you decide to test it out.

First create a custom function in PHP, let's name it send_error_email().
PHP Code:

<?php
//  FILENAME: FUNCTIONS.INC.PHP

function send_error_email( $error_code='Undefined' )
{  
  // set the TO: email address
  $to = 'admin@example.com';

  // the referring page, if any
  $referred_by = ( isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Unknown' );
  
  $subject = "An error has occured - type: $error_code";    

  $message = "The following error has occured:\r\n"
            ."--------------------------------\r\n\r\n"
            ."  Type          : $error_code\r\n"
            ."  Page          : {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\r\n"
            ."  Referred from : $referred_by\r\n"
            ."  Time          : ".date('d/m/Y H:i:s')."\r\n"
            ."  From IP       : {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
            ."Regards,\r\n"
            ."Your hard-working web server.";

  $headers = "From: webserver@{$_SERVER['SERVER_NAME']}\n"
            ."Reply-To: webserver@{$_SERVER['SERVER_NAME']}\n"
            ."X-Mailer: PHP/".phpversion();

  // send the email
  mail( $to, $subject, $message, $headers );
}
?>


So, now, in your file named 404.php, you could simply add the following lines:
PHP Code:

<?php
// FILENAME: 404.PHP

// include the filenamed : functions.inc.php...
// assuming that both files are in the same directory
include_once( $_SERVER['DOCUMENT_ROOT'].'/functions.inc.php' );

// Everytime someone reaches this page, i.e. 404.php, an email gets sent out
send_error_email( '404' );

// the rest of the html output / script below...

?>


Like I mentioned earlier in my post, I haven't tested whether it gives you correct information nor that the code I wrote above actually works. I'll appreciate your feedback though.
  #3  
Old 18-Aug-2003, 03:06
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Parse error: parse error, unexpected '<' in /home/mrbobdou/public_html/errorpgs/404.php on line 18

HTML Code:
<?php // FILENAME: 404.PHP // include the filenamed : functions.inc.php... // assuming that both files are in the same directory include_once( 'functions.inc.php' ); // Everytime someone reaches this page, i.e. 404.php, an email gets sent out send_error_email( '404' ); <html> <head> <title>.:. Mr. Bob's Web Design .:. 404 Error .:. Web Design, Hosting, Marketing, Search Engine Submissions, Web Site Optimization, Guaranteed Search Engine Submission, For everyone!</title> <style> td{font-family:Tahoma;font-size:11px;color:#ffffff} </style> <LINK rel = STYLESHEET href = "http://mrbobdouglas.com/scripts/main.css" Type = "text/css" > <script src="http://mrbobdouglas.com/scripts/pop_up.js" type="text/javascript"></script> </head> <body topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0"> <table cellpadding="0" cellspacing="0" border="0" height="100%"> <tr> <td rowspan="9" width="50%" height="100%" background="http://mrbobdouglas.com/images/line1.jpg" style="background-position:right top; background-repeat:repeat-y"></td> <td rowspan="9" width="1" bgcolor="#000000"></td> <td height="100%" background="http://mrbobdouglas.com/images/bgs.jpg"> <table cellpadding="0" cellspacing="0" border="0" height="100%"> <tr> <td><img src="http://mrbobdouglas.com/images/subheaderMiddle.jpg" width="545" height="28"></td> </tr> <tr> <td width="545" height="100%" background="http://mrbobdouglas.com/images/bgs1.jpg" style="background-repeat:no-repeat;background-position:top;" valign="top" style="padding-top:10px;padding-left:55px;"> &nbsp;<div style="padding-top:10px;padding-left:20px;padding-right:20px;"> <h2><font color="#FEB201">404 ERROR:</font></h2> <p>Page name: &lt;?pagename&gt;</p> <p>Page not found - client tried to access a page not on the server.</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>An e-mail has been sent to the Webmaster concerning the page you were trying to access.</p> <p><a href="http://www.mrbobdouglas.com">[url]www.mrbobdouglas.com[/url]</a> </p> </div> </td> </tr> <tr> <td><img src="http://mrbobdouglas.com/images/subheaderBottom.jpg" width="545" height="35"></td> </tr> </table> </td> <td rowspan="9" width="1" bgcolor="#000000"></td> <td rowspan="9" width="50%" height="100%" background="http://mrbobdouglas.com/images/line2.jpg" style="background-position:left top; background-repeat:repeat-y"></td> </tr> </table> </body> </html> ?>

PHP Code:

<?php

//  FILENAME: FUNCTIONS.INC.PHP



function send_error_email( $error_code='Undefined' )

{  

  // set the TO: email address

  $to = 'bobbydouglas@cox.net';

  

  $subject = "An error has occured - type: $error_code";    



  $message = "The following error has occured:\r\n"

            ."--------------------------------\r\n\r\n"

            ."  Type: $error_code\r\n"

            ."  Page:  {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}
\r\n"

            ."  Time: ".date('d/m/Y H:i:s')."\r\n"

            ."  From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"

            ."Regards,\r\n"

            ."Your hard-working web server.";



  $headers = "From: webserver@{$_SERVER['SERVER_NAME']}\n"

            ."Reply-To: webserver@{$_SERVER['SERVER_NAME']}\n"

            ."X-Mailer: PHP/".phpversion();



  // send the email

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

}

?>



Did I miss something? Both files are located at the errorpgs directory.
  #4  
Old 18-Aug-2003, 03:56
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Try this instead:
PHP Code:

<?php
// FILENAME: 404.PHP

// include the filenamed : functions.inc.php...
// assuming that both files are in the same directory
include_once( 'functions.inc.php' );

// Everytime someone reaches this page, i.e. 404.php, an email gets sent out
send_error_email( '404' );
?>
<html>
<head>
  <title>.:. Mr. Bob's Web Design .:. 404 Error .:. Web Design, Hosting, 
    Marketing, Search Engine Submissions, Web Site Optimization, Guaranteed 
    Search Engine Submission, For everyone!</title>
<style>
td{font-family:Tahoma;font-size:11px;color:#ffffff}
    </style>
<LINK   rel     =  STYLESHEET
                href    = "http://mrbobdouglas.com/scripts/main.css"
                Type    = "text/css"    >
<script src="http://mrbobdouglas.com/scripts/pop_up.js"
        type="text/javascript"></script>
</head>

<body topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0">
<table cellpadding="0" cellspacing="0" border="0" height="100%">
<tr>
  <td rowspan="9" width="50%" height="100%" background="http://mrbobdouglas.com/images/line1.jpg" style="background-position:right top; background-repeat:repeat-y"></td>
  <td rowspan="9" width="1" bgcolor="#000000"></td>
  <td height="100%" background="http://mrbobdouglas.com/images/bgs.jpg">
  <table cellpadding="0" cellspacing="0" border="0" height="100%">
    <tr>
      <td><img src="http://mrbobdouglas.com/images/subheaderMiddle.jpg" width="545" height="28"></td>      
    </tr>
    <tr>
      <td width="545" height="100%" background="http://mrbobdouglas.com/images/bgs1.jpg" style="background-repeat:no-repeat;background-position:top;" valign="top" style="padding-top:10px;padding-left:55px;">
      &nbsp;<div style="padding-top:10px;padding-left:20px;padding-right:20px;">
              <h2><font color="#FEB201">404 ERROR:</font></h2>
              <p>Page name: &lt;?pagename></p>
              <p>Page not found - client tried to access a page not on the 
              server.</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>An e-mail has been sent to the Webmaster concerning the page 
              you were trying to access.</p>
              <p><a href="http://www.mrbobdouglas.com">www.mrbobdouglas.com
</a> </p>
            </div>
      </td>
    </tr>
    <tr>
      <td><img src="http://mrbobdouglas.com/images/subheaderBottom.jpg" width="545" height="35"></td>
    </tr>
  </table>
  </td>
  <td rowspan="9" width="1" bgcolor="#000000"></td>
  <td rowspan="9" width="50%" height="100%" background="http://mrbobdouglas.com/images/line2.jpg" style="background-position:left top; background-repeat:repeat-y"></td>  
</tr>

</table>
</body>
</html>
  #5  
Old 18-Aug-2003, 04:19
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Done. Now even more.
[ERROR]
Warning: main(functions.inc.php) [function.main]: failed to create stream: No such file or directory in /home/mrbobdou/public_html/errorpgs/404.php on line 11

Warning: main() [function.main]: Failed opening 'functions.inc.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/mrbobdou/public_html/errorpgs/404.php on line 11

Fatal error: Call to undefined function: send_error_email() in /home/mrbobdou/public_html/errorpgs/404.php on line 17
[/ERROR] <-- Wonders if this will work or not.
  #6  
Old 18-Aug-2003, 04:36
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Oh, I didn't notice that you had changed this line:
PHP Code:

include_once( 'functions.inc.php' ); 



In 404.php, that line should look like this:
PHP Code:

include_once( './functions.inc.php' ); 



Haven't figured out what to do with a [error] tag yet...
  #7  
Old 18-Aug-2003, 04:51
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

About your 404 Error page...


Just how is your 404 page being triggered?

From my own tests with some fake pages on your website, I can say with some degree of certainty that the code above is not going to work.

On my own 404 page, you will see that the wrong URL is maintained in the address bar. Ignore the white font on 'white', I just haven't updated the CSS for that page since my last re-design.

To trigger my 404 NOT Found errors, I added the following line to my .htaccess file in http://www.desilva.biz/.htaccess:
Code:
ErrorDocument 404 /error404.php
  #8  
Old 18-Aug-2003, 05:03
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
I am not sure exactly how they work. What I have done is gone to my 'Settings' then 'Error pages' and used an 'External Page' http://www.mrbobdouglas.com/errorpgs/NameOfError.php

For the 404, it is http://www.mrbobdouglas.com/errorpgs/404.php

This is what my .htaccess looks like:
ErrorDocument 403 /ipw-web/errdocs/403.html
ErrorDocument 401 /ipw-web/errdocs/401.html
ErrorDocument 500 /ipw-web/errdocs/500.html
ErrorDocument 400 /ipw-web/errdocs/400.html
ErrorDocument 404 /ipw-web/errdocs/404.html
ErrorDocument 404 http://www.mrbobdouglas.com/errorpgs/404.php

Make note the only one repeating is the 404 error that i said i had made external- which could be why I get the problem

Should I call tech support? What would I ask them? 1-888-511-4678
  #9  
Old 18-Aug-2003, 05:10
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Well... I just called them, they said they are going to put me through with a programmer some time in about 4 hours when he arrives.
  #10  
Old 18-Aug-2003, 05:21
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
I just got an e-mail. But it said the page of the 404.php...

However, I tried it agaig, and now I did not get an e-mail.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:28.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.