4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: antonio2005 on June 30, 2006, 04:35:22 PM

Title: [REQ] Custom Mysql error pages
Post by: antonio2005 on June 30, 2006, 04:35:22 PM
Hi,

I think that it it a nice idea, to look at the way 4homepages handles mysql errors.

For example, if a site as reached max_user, instead of showing an Warning message with technical informations about the error, it would be nice to display a page based on the site template, saying something like:
"Due to high traffic, the page you are trying to see is not available. Please try again in a few minutes. Even so the wemaster will posted about this occurence."

What do our masters think about this idea?

I'm sorry not to know a little of php and sql.


Thanks in advance, and continue the excelent job,
António
Title: Re: [REQ] Custom Mysql error pages
Post by: V@no on July 01, 2006, 12:13:19 AM
This also was my concern and the only way I see at the moment is supress all these errors and only show them to admins.

For that you can do the following:
in includes/db_mysql.php find:
Code: [Select]
  var $table_fields = array();
Insert below:
Code: [Select]
  var $errors = array();

Then find:
Code: [Select]
      echo "<br /><font color='#FF0000'><b>DB Error</b></font>: ".$errmsg."<br />";
      if ($halt) {
Replace with:
Code: [Select]
      $this->errors[] = "<br /><font color='#FF0000'><b>DB Error</b></font>: ".$errmsg."<br />";
      if ($halt) {
        global $user_info;
        if ((isset($user_info['user_level']) && $user_info['user_level'] == ADMIN) || $_SERVER['REMOTE_ADDR'] == "127.0.0.1")
        {
          echo "<pre>";
          print_r($this->errors);
        }

After that, in includes/page_footer.php find:
Code: [Select]
$site_db->close();
Insert above:
Code: [Select]
if (!empty($site_db->errors) && $user_info['user_level'] == ADMIN)
{
  echo "<div><pre>";
  print_r($site_db->errors);
  echo "</pre></div>";
}

optionaly in second step you can replace 127.0.0.1 with your computer's IP (the IP of the computer that you use to visit your site from)
Title: Re: [REQ] Custom Mysql error pages
Post by: mawenzi on July 01, 2006, 12:53:06 AM
... I like this idea ... so I tried a variant of your first version ...

Code: [Select]
function error($errmsg, $halt = 0) {
    if (!$this->no_error) {
      global $user_info;
      if (!isset($user_info['user_level']) || $user_info['user_level'] == ADMIN){
       echo "<br /><font color='#FF0000'><b>DB Error</b></font>: ".$errmsg."<br />";
      } else {
       echo "<br /><font color='#FF0000'><b>DB Error</b></font> :<br />";
       echo" Due to high traffic, the page you are trying to see is not correctly available...<br />";
      }
      if ($halt) {
        exit;
      }
    }
  }

... of course the DB-errors would be shown only for logged in admins ...
Title: Re: [REQ] Custom Mysql error pages
Post by: V@no on July 01, 2006, 02:26:25 AM
... of course the DB-errors would be shown only for logged in admins ...

Thats the problem - it will show errors to everyone, unless the error ocured after session initialization, which is doubtfull in case connection limit error...that's why I've changed it and added IP check in case of error before session initialization...
Title: Re: [REQ] Custom Mysql error pages
Post by: antonio2005 on July 01, 2006, 08:16:13 PM
Great. Thanks Vano, you are allways one step ahead!

I believe that the initial post is more than 50% solved.

Anyone with an idea on how to show up a costum error page ?

Thanks and Regards,
António
Title: Re: [REQ] Custom Mysql error pages
Post by: antonio2005 on July 02, 2006, 11:57:15 AM
Hi again,

Heres something i found at linuxguruz.org, that may be usefull:



# First create a MySQL error handing function
# Call this file mysql_error.inc
#
<?
function this_error () {
$url = "http://www.linuxguruz.org"; // Your URL goes here
$doc = "error.html";          // Error doc name
$errno = mysql_errno();
$error = urlencode(mysql_error());
$day = urlencode(date("l dS of F Y h:i a"));
include "$url/$doc?errno=$errno&error=$error&today=$day";
}
?>



# Next create a test page
# Call this file test.html
#
<HTML><BODY><?
include "mysql_error.inc";
@mysql_select_db("nonexistentDB")
or die(this_error());
?></BODY></HTML>



# Now create a the page the user will be directed to
# Call this file error.html
#
<HTML><BODY>
<HEAD>
<META HTTP-EQUIV=REFRESH
 CONTENT="10;URL=http://www.linuxguruz.org">
</HEAD>
<?
$fp = popen("/usr/sbin/sendmail -t", "w");
$num = fputs($fp, "To: webmaster@linuxguruz.org\n");
$num += fputs($fp, "From: MySQL_ERROR\n");
$num += fputs($fp, "Subject: MySQL Error Submition\n\n");
$message = "Error Number: $errno\n";
$message .= "Error Cause:  $error\n";
$message .= "Date:         $today\n";
$num += fputs($fp, "$message");
pclose($fp); ?>
<CENTER><B>
A error has occured while proccesing your request
</B></CENTER>
<A HREF="mailto:webmaster@linuxguruz.org">
webmaster@linuxguruz.org </A>has been notified.<P>
You will be returned to our Main site in 10 seconds.
</BODY></HTML>



# Lastly customize the error page to best meet your sites
# needs. You need to change the 5 occurances of the domain
# linuxguruz.org to your own domain name. As you can see
# the error.html file is very configurable and I am shure
# you can see the possibilities.