diff --git a/phpBB/common.php b/phpBB/common.php
index d9cdc61dbc..3d74b83583 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -70,14 +70,14 @@ include('includes/db.'.$phpEx);
//
if(!empty($HTTP_CLIENT_IP))
{
- if(eregi("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER))
+ if(ereg("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_CLIENT_IP))
{
$client_ip = $HTTP_CLIENT_IP;
}
}
else if(!empty($HTTP_X_FORWARDED_FOR))
{
- if(strstr(",", $HTTP_X_FORWARDED_FOR))
+ if(ereg(",", $HTTP_X_FORWARDED_FOR))
{
list($client_ip) = explode(",", $HTTP_X_FORWARDED_FOR);
}
@@ -88,14 +88,14 @@ else if(!empty($HTTP_X_FORWARDED_FOR))
}
else if(!empty($HTTP_VIA))
{
- if(eregi("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER))
+ if(ereg("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_VIA))
{
$client_ip = $HTTP_VIA;
}
}
else if(!empty($HTTP_PROXY_USER))
{
- if(eregi("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER))
+ if(ereg("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", $HTTP_PROXY_USER))
{
$client_ip = $HTTP_PROXY_USER;
}
@@ -106,27 +106,15 @@ else
}
$user_ip = encode_ip($client_ip);
-
//
-// Setup forum wide options.
-// This is also the first DB query/connect
+// Setup forum wide options, if this fails
+// then we output a CRITICAL_ERROR since
+// basic forum information is not available
//
$sql = "SELECT *
FROM " . CONFIG_TABLE;
if(!$result = $db->sql_query($sql))
{
- //
- // Define some basic configuration
- // vars, necessary since we haven't
- // been able to get them from the DB
- //
- $board_config['default_template'] = "Default";
- $board_config['default_timezone'] = 0;
- $board_config['default_dateformat'] = "d M Y H:i";
- $board_config['default_theme'] = 1;
- $board_config['default_lang'] = "english";
- $board_config['gzip_compress'] = 0;
-
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
}
else
@@ -170,7 +158,6 @@ else
$board_config['gzip_compress'] = $config['gzip_compress'];
$board_config['smtp_delivery'] = $config['smtp_delivery'];
$board_config['smtp_host'] = $config['smtp_host'];
-
}
include('language/lang_' . $board_config['default_lang'] . '.'.$phpEx);
diff --git a/phpBB/includes/message.php b/phpBB/includes/message.php
index afb915dd29..1a0e1126d7 100644
--- a/phpBB/includes/message.php
+++ b/phpBB/includes/message.php
@@ -22,28 +22,47 @@
*
***************************************************************************/
+//
+// This function gets called to output any message or error
+// that doesn't require additional output from the calling
+// page.
+//
+// $msg_code takes one of four constant values:
+//
+// GENERAL_MESSAGE -> Use for any simple text message, eg.
+// results of an operation, authorisation failures, etc.
+//
+// GENERAL ERROR -> Use for any error which occurs _AFTER_
+// the common.php include and session code, ie. most errors
+// in pages/functions
+//
+// CRITICAL_MESSAGE -> Only currently used to announce a user
+// has been banned, can be used where session results cannot
+// be relied upon to exist
+//
+// CRITICAL_ERROR -> Used whenever a DB connection cannot be
+// guaranteed and/or sessions have failed. Shouldn't be used
+// in general pages/functions (it results in a simple echo'd
+// statement, no templates are used)
+//
function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "", $err_file = "", $sql = "")
{
-
global $db, $template, $board_config, $theme, $lang, $phpEx;
global $userdata, $user_ip, $session_length;
global $starttime;
- if(empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) )
+ if( empty($userdata) && ( $msg_code == GENERAL_MESSAGE || $msg_code == GENERAL_ERROR ) )
{
- //
- // Start session management
- //
$userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length);
init_userprefs($userdata);
- //
- // End session management
- //
}
-
- if(!defined("HEADER_INC"))
+
+ //
+ // If the header hasn't been output then do it
+ //
+ if( !defined("HEADER_INC") && $msg_code != CRITICAL_ERROR )
{
- if(!empty($board_config['default_lang']))
+ if( !empty($board_config['default_lang']) )
{
include('language/lang_' . $board_config['default_lang'] . '.'.$phpEx);
}
@@ -51,18 +70,21 @@ function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "",
{
include('language/lang_english.'.$phpEx);
}
- if(!$template)
+
+ if( empty($template) )
{
$template = new Template("templates/Default");
}
- if(!$theme)
+
+ if( empty($theme) )
{
$theme = setuptheme(1);
}
- if($msg_code != CRITICAL_ERROR)
- {
- include('includes/page_header.'.$phpEx);
- }
+
+ //
+ // Load the Page Header
+ //
+ include('includes/page_header.'.$phpEx);
}
switch($msg_code)
@@ -86,57 +108,83 @@ function message_die($msg_code, $msg_text = "", $msg_title = "", $err_line = "",
{
$msg_text = $lang['An_error_occured'];
}
+
if($msg_title == "")
{
$msg_title = $lang['General_Error'];
}
case CRITICAL_ERROR:
+ //
+ // Critical errors mean we cannot rely on _ANY_ DB information being
+ // available so we're going to dump out a simple echo'd statement
+ //
+ include('language/lang_english.'.$phpEx);
+
if($msg_text == "")
{
$msg_text = $lang['A_critical_error'];
}
+
if($msg_title == "")
{
- $msg_title = $lang['Critical_Error'];
+ $msg_title = "phpBB : " . $lang['Critical_Error'] . "";
}
break;
}
+
+ //
+ // Add on DEBUG info if we've enabled debug mode and this is an error. This
+ // prevents debug info being output for general messages should DEBUG be
+ // set TRUE by accident (preventing confusion for the end user!)
+ //
if(DEBUG && ( $msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR ) )
{
$sql_error = $db->sql_error();
$debug_text = "";
+
if($sql_error['message'] != "")
{
$debug_text .= "
SQL Error : " . $sql_error['code'] . " " . $sql_error['message'];
}
+
if($sql != "")
{
$debug_text .= "
$sql";
}
+
if($err_line != "" && $err_file != "")
{
$debug_text .= "
Line : " . $err_line . "
File : " . $err_file;
}
+
if($debug_text != "")
{
$msg_text = $msg_text . "
DEBUG MODE" . $debug_text;
}
}
- $template->set_filenames(array(
- "message_body" => "message_body.tpl")
- );
- $template->assign_vars(array(
- "MESSAGE_TITLE" => $msg_title,
- "MESSAGE_TEXT" => $msg_text)
- );
- $template->pparse("message_body");
+ if( $msg_code != CRITICAL_ERROR )
+ {
+ $template->set_filenames(array(
+ "message_body" => "message_body.tpl")
+ );
+ $template->assign_vars(array(
+ "MESSAGE_TITLE" => $msg_title,
+ "MESSAGE_TEXT" => $msg_text)
+ );
+ $template->pparse("message_body");
- include('includes/page_tail.'.$phpEx);
+ include('includes/page_tail.'.$phpEx);
+ }
+ else
+ {
+ echo "\n