"Illegal string offset 'lang_selected'" warnings

Found a bug? Tell us!!
Post Reply
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

"Illegal string offset 'lang_selected'" warnings

Post by wesley »

Looking at the error logs of my webserver, I've noticed this error cropping up every so often:

Code: Select all

PHP Warning: Illegal string offset 'lang_selected' in (server path)/include/functions_config.inc.php on line 993
I'm using the multilingual plugin (serendipity_plugin_multilingual), of course, so the blog's display language can be selected. But selecting the display language, or choosing a certain language version of a blog entry did not cause this error. If a certain action was causing it, it would have to be something else.

To pinpoint the cause, I've cross-checked the access log of the server with the error. The error apparently occurred when a page request is made in the form of:

Code: Select all

http://(blog URL)/index.php?url=archives/(blog page).html&serendipity
Note the "&serendipity" part - it's missing something like [lang_selected]=default, i.e.:

Code: Select all

http://(blog URL)/index.php?url=archives/(blog page).html&serendipity[lang_selected]=default
So I've crafted the URL in the same manner as the first one, and was able to recreate the error message. Curiously, this does NOT generate an error, though:

Code: Select all

http://(blog URL)/archives/(blog page).html&serendipity
The only difference is that it's omitting "index.php?url=" part.

I can't prevent someone entering a malformed URL - these requests were tracked down to a spam bot in Ukraine. But I would like the functions_config_inc.php to handle the error gracefully so that a PHP warning isn't issued every time. The code around line 993 is:

Code: Select all

elseif (!empty($serendipity['languages'][$serendipity['GET']['lang_selected']])) {
    if ($serendipity['expose_s9y']) serendipity_header('X-Serendipity-InterfaceLangSource: GET');
    $lang = $serendipity['GET']['lang_selected'];
}
So I'm guessing that, when "&serendipity" is appended to the URL, "lang_selected" gets a certain value, but since the problematic URL does not have one specified, an "illegal string offset" error is generated. Perhaps an error-trapping code could be inserted?

P.S. I'm currently using version 1.7.8.
I make s9y plugins, too.
My s9y blog depends on them. :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: "Illegal string offset 'lang_selected'" warnings

Post by garvinhicking »

Hey,

thanks, great catch. I believe a patch like this should do:

Code: Select all

diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php
index 6210b90..b912710 100644
--- a/include/functions_config.inc.php
+++ b/include/functions_config.inc.php
@@ -969,7 +969,7 @@ function serendipity_getSessionLanguage() {
     if (isset($serendipity['COOKIE']['serendipityLanguage'])) {
         if ($serendipity['expose_s9y']) serendipity_header('X-Serendipity-InterfaceLangSource: Cookie');
         $lang = $serendipity['COOKIE']['serendipityLanguage'];
-    } elseif (!empty($serendipity['languages'][$serendipity['GET']['lang_selected']])) {
+    } elseif (isset($serendipity['GET']['lang_selected']) && !empty($serendipity['languages'][$serendipity['GET']['lang_selected']])) {
         if ($serendipity['expose_s9y']) serendipity_header('X-Serendipity-InterfaceLangSource: GET');
         $lang = $serendipity['GET']['lang_selected'];
     } elseif (serendipity_db_bool($serendipity['lang_content_negotiation'])) {
(patch is against git head, but should apply to 1.7.8. similarly, or apply manually (only add the isset(...)).

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: "Illegal string offset 'lang_selected'" warnings

Post by wesley »

I manually edited the file to replace that one line, and now the error no longer pops up. Thank you. :D
I make s9y plugins, too.
My s9y blog depends on them. :)
Post Reply