Author Topic: [REQ] Custom Mysql error pages  (Read 5476 times)

0 Members and 1 Guest are viewing this topic.

Offline antonio2005

  • Newbie
  • *
  • Posts: 11
    • View Profile
[REQ] Custom Mysql error pages
« 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

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [REQ] Custom Mysql error pages
« Reply #1 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)
« Last Edit: July 01, 2006, 12:25:31 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: [REQ] Custom Mysql error pages
« Reply #2 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 ...
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [REQ] Custom Mysql error pages
« Reply #3 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...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline antonio2005

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: [REQ] Custom Mysql error pages
« Reply #4 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

Offline antonio2005

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: [REQ] Custom Mysql error pages
« Reply #5 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.