Multiple UTF8 and related errors in Sources/Subs-post.php

Started by Mark S, September 25, 2020, 12:24:49 AM

Previous topic - Next topic

Mark S

Upgraded to 2.0.17 a couple months ago.  Everything was great.  No errors in the error log.  But, starting a couple weeks ago, I started getting the following errors.

They all are associated with "Guest" actions.

All have this at the beginning:
https://www.classicwinnebagos.com/forum/index.php?scheduled=task;ts=1600992000

The following are the repetitive errors and corresponding code:

First error:

8: Undefined index: server
File: /home/xxxxxxxx/public_html/forum/Sources/Subs-Post.php
Line: 627

626:      // Line breaks need to be \r\n only in windows or for SMTP.
==>627:      $line_break = $context['server']['is_windows'] || !$use_sendmail ? "\r\n" : "\n";

Second error:

8: Undefined index: character_set
File: /home/xxxxxxxx/public_html/forum/Sources/Subs-Post.php
Line: 1219

1214:   // Prepare text strings for sending as email body or header.
1215:   function mimespecialchars($string, $with_charset = true, $hotmail_fix = false, $line_break = "\r\n", $custom_charset = null)
1216:   {
1217:      global $context;
1218:   
==>1219:      $charset = $custom_charset !== null ? $custom_charset : $context['character_set'];

Third and fourth errors:

8: Undefined index: utf8
File: /home/xxxxxxxx/public_html/forum/Sources/Subs-Post.php
Line: 1262
Line: 1264

1261:      // Convert all special characters to HTML entities...just for Hotmail :-\
==>1262:      if ($hotmail_fix && ($context['utf8'] || function_exists('iconv') || $context['character_set'] === 'ISO-8859-1'))
1263:      {
==>1264:         if (!$context['utf8'] && function_exists('iconv'))

I'm not sure how this affects anything.  I don't see anything weird, but it's a constant, everyday thing.

Help with fixing it greatly appreciated.

shawnb61

This is an old bug, and has been around a while:
https://www.simplemachines.org/community/index.php?topic=546745.0

It does not impact anything, so has been a low priority.  What changed in 2.0.16/17 was the error logging.  Prior to 2.0.16, many errors were not reported, & would only show up in the apache logs, if at all.  That was fixed.  So...  Now some of these old issues are more visible; they are trapped & reported properly in the SMF error log instead of being buried in the apache log. 

These errors appear under certain circumstances when mailings are sent out, usually the daily & weekly digests.  Many of us see a burst of them weekly with the weekly digest. 

TL;DR: Don't worry about them.  If volume is absurdly high for some reason, we can work something out.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Sir Osis of Liver

If it really bothers you, the errors can be eliminated by defining the indexes (indeces?) before they're called. 



/// Fudge to remove undefined errors from scheduled tasks
if (!isset($context['server']))
$context['server'] = null;


Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Mark S

Thanks for the explanation.
Where do I insert that code?  It shows "select" but I don't find that anywhere in the Subs-Post.php file.
Much appreciated!

shawnb61

This is the one I use on my site.  In ScheduledTasks.php, at the end of loadEssentialThemeData(), towards the end, you will find:

loadLanguage('index+Modifications');

Replace it with:

loadLanguage('index+Modifications');

// Also load up some context that is used by routines throughout ScheduledTasks.
// These may not be set when AutoTask is called very early in index.php.
// When scheduled tasks throw undefined errors, address them here.

if (!isset($context['server']))
{
// Copied over from Load.php...
// This determines the server... not used in many places, except for login fixing.
$context['server'] = array(
'is_iis' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false,
'is_apache' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false,
'is_lighttpd' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false,
'is_nginx' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false,
'is_cgi' => isset($_SERVER['SERVER_SOFTWARE']) && strpos(php_sapi_name(), 'cgi') !== false,
'is_windows' => strpos(PHP_OS, 'WIN') === 0,
'iso_case_folding' => ord(strtolower(chr(138))) === 154,
'complex_preg_chars' => @version_compare(PHP_VERSION, '4.3.3') != -1,
);
}

if (!isset($context['utf8']))
{
// Copied over from Load.php...
// Set the character set from the template.
$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
$context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1);
$context['right_to_left'] = !empty($txt['lang_rtl']);
}



You may need to revert this change prior to applying a future patch.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Mark S


Advertisement: