ElkArte Community

Project Support => Support => Topic started by: Mrs. Chaos on October 10, 2021, 02:45:21 pm

Title: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 10, 2021, 02:45:21 pm
Hi,
When I try to access a user's profile, the message "Undefined variable: key" now appears. What's wrong there?
This is displayed in the error log:

Type of error: Undefined
Notice: Undefined variable: key
https://forum.xxx.de/index.php?action=profile

File: /www/htdocs/xxx/xxx/sources/subs/Profile.subs.php
Line: 293

Code: [Select]
291		if (in_array($row['field_type'], array('radio', 'select')))
292 {
293 $replacements['{KEY}'] = $row['col_name'] . '_' . $key;
294 }
295 $output_html = strtr($row['enclose'], $replacements);


Maybe the error has to do with this error message for the addon "Stop Spammer":

Type of error: Undefined
Notice: Undefined index: stopspammer_profilecheck
https://forum.xxx.de/index.php?action=profile

File: /www/htdocs/xxx/xxx/sources/addons/StopSpammer/StopSpammer_hooks.php
Line: 465

Code: [Select]
457	   // Add "Check this member" under "Action" menu in individual profile view
458    public static function profile_areas(&$profile_areas)
459    {
460    global $txt, $scripturl, $memID, $modSettings;
461    loadLanguage('StopSpammer');
462
463    $profile_areas['profile_action']['areas'] = elk_array_insert($profile_areas['profile_action']['areas'], 'activateaccount', array(
464       'checkmember' => array(
465      'label' => $txt['stopspammer_profilecheck'],
466    'custom_url' => $scripturl . '?action=admin;area=viewmembers;sa=query;params=' . base64_encode(serialize(array('mem_id' => $memID, 'types' => array('mem_id' => '=')))),
467    'enabled' => !empty($modSettings['stopspammer_enable']),
468    'sc' => 'get',
469    'permission' => array(
470    'own' => array('profile_remove_any', 'profile_remove_own'),
471    'any' => array('profile_remove_any', 'moderate_forum'),
472    ),
473    )), 'after');
474    }
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: badmonkey on October 10, 2021, 04:09:44 pm
Are you running php8 by chance? I get the same error in 8, but not 7.4
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 10, 2021, 04:30:06 pm
Yes, three days ago I switched from PHP 7.4 to 8.0 ...
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: badmonkey on October 10, 2021, 05:10:50 pm
Yes, three days ago I switched from PHP 7.4 to 8.0 ...


Worth mentioning here, I don't get the error on every install....
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 10, 2021, 05:54:19 pm
However, I believe that the error was already there before the change to PHP 8.0. Unfortunately, I deleted all error messages before that, so now I can't track when it was first reported.
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Spuds on October 10, 2021, 07:01:29 pm
Looks like a small bug in the custom profile fields area, probably pretty old as well.  PHP8 is less forgiving which is a good thing really.

I'm not at a place where I can do any testing, but you can try the following to prevent the warning.
Code: (find) [Select]
			{ 
$replacements['{KEY}'] = $row['col_name'] . '_' . $key;
}
with
Code: (replace) [Select]
			{
$key = $key ?? 0;
$replacements['{KEY}'] = $row['col_name'] . '_' . $key;
}
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 10, 2021, 08:16:19 pm
The error message no longer appears, maybe it helped.
However, I still can't view members' profiles, not even my own. And now I can't get into my user account to change anything there either.
Furthermore, the Stop Spammer error mentioned in the start post is still displayed in the error messages. Another one appears when I click on "Members" or "Show Members" in the Admin Center. This is reported then:

Type of error: Undefined
Warning: Undefined array key "stopspammer_count"
https://forum.xxx.de/index.php?action=admin;area=viewmembers;DB9BDCAT42wv=....

File: /www/htdocs/xxx/xxx/sources/addons/StopSpammer/StopSpammer_hooks.php
Line: 390

Code: [Select]
386	$add = array( !$modSettings['stopspammer_enable'] ? '' :
387 array(
388 'position' => 'below_table_data',
389 'value' => '
390 <div style="text-align: center">' . $modSettings['stopspammer_count'] . ' ' . $txt['stopspammer_count'] . '</div>',
391 'class' => 'titlebg',
392 ),


Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Spuds on October 10, 2021, 11:32:51 pm
I'd suggest disabling that addon and see what errors you are getting.  I'm not familiar with that addon so I don't know if there is a problem with it and php8 or some other issue.
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 11, 2021, 06:00:04 am
I have thought of that too. I will test it later today.
Is Stop Spammer still good for spam defence at all? This addon was last updated 4 or 5 years ago. The same goes for StopForumSpam. Both authors don't seem to be active in the forum since then either.
Is there a better alternative to these addons?
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 11, 2021, 11:43:36 am
Disabling Stop Spammer didn't help. The messages Undefined array key "stopspammer_profilecheck" and Undefined array key "stopspammer_count" still appear.

Do you think I should continue posting in the Addons board in the "Stop Spammer" topic because of the errors?
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Spuds on October 11, 2021, 04:45:47 pm
I'm not at all familiar with the addon, so I can't comment on its effectiveness. 

If you have disabled the addon, and are still getting errors about it, then that means its still somehow active?  Did you disable or remove the addon?
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 11, 2021, 05:46:06 pm
First it was only deactivated, now I have deleted it completely including links to somewhere in the forum.
The old error messages seem to have disappeared, but I still can't display any profiles and in addition I now can't open any threads or single posts... :o
This database error is now reported for everything:

Type of error: database
Database error: Unknown column 'mem.is_spammer' in 'field list'

https://forum.xxx.de/index.php?action=profile;u=1
https://forum.xxx.de/index.php?topic=472.msg7215
https://forum.xxx.de/index.php?topic=456.0

File: /www/htdocs/xxx/xxx/sources/Load.php
Line: 1005

Code: [Select]
998		// Load the member's data.
999 $request = $db->query('', '
1000 SELECT' . $select_columns . '
1001 FROM {db_prefix}members AS mem' . $select_tables . '
1002 WHERE mem.' . ($is_name ? 'member_name' : 'id_member') . (count($users) == 1 ? ' = {' . ($is_name ? 'string' : 'int') . ':users}' : ' IN ({' . ($is_name ? 'array_string' : 'array_int') . ':users})'),
1003 array(
1004 'blank_string' => '',
1005 'users' => count($users) == 1 ? current($users) : $users,
1006 )
1007 );
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Spuds on October 11, 2021, 06:03:53 pm
That basically means the "hooks" were not removed during uninstall. 

You should be able to delete the StopSpammer.integration.php file from your sources directory.  The hooks (in this case) are stored in the db and ideally should be removed at some point.
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 11, 2021, 07:54:30 pm
I deleted it there and now everything is OK again. Everything is displayed normally. I clicked around wildly in the forum and nothing triggered an error message. Perfect!
Thanks a lot for your help, Spuds! :)
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: tino on October 12, 2021, 09:07:53 pm
Which Stop Spammer Integration was this? As in was it mine 😂
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: Mrs. Chaos on October 13, 2021, 03:25:14 pm
It was this addon:
https://www.elkarte.net/community/index.php?topic=4277.0

I think yours is this one:
https://addons.elkarte.net/security/StopForumSpam.html

Is yours still up to date and does it work with Elkarte version 1.1.8 ?
If so, I will install it. :)
Title: Re: Error message "Undefined variable: key" for the Profile.subs.php
Post by: tino on October 13, 2021, 06:43:28 pm
Honestly I’ve not tried it yet. It’s running on my site on 1.1.7 and PHP 7.4.

I’ll try and find some time to test on the latest. Was more if you have any bugs to report I could resolve them.