Error Message in Register form

I was testing some things on the site today and I came across an error message. If you are an unregistered user and you go to the “Register” section to create a new profile ([url]https://www.yoursite.com/index.php?dispatch=profiles.add[/url])



I didn’t fill anything in and clicked “Register” at the bottom … it performed the Ajax stuff to tell me that I need to fill in everything however at the very top of the page was this error message



Warning: Invalid argument supplied for foreach() in /home/racingso/public_html/controllers/common/profiles.post.php on line 235



I looked at the code and it has to do with Usergroups … Just curious if anyone else gets this error message. I’m on 2.0.11 also. Line 235 is the Foreach statement



This is the code snippet from profiles.post.php



$usergroups = fn_get_usergroups((!empty($user_data['user_type']) && $user_data['user_type'] == 'A' ? 'F' : 'C'), CART_LANGUAGE);
if (AREA != 'A' && Registry::get('settings.General.allow_usergroup_signup') != 'Y') {
$hide_tab = true;
foreach ($user_data['usergroups'] as $_user_group) {
if ($_user_group['status'] == 'A') {
$hide_tab = false;
break;
}
}
if ($hide_tab) {
$usergroups = array();
}
}

I have the same problem , i just see it today

i dont know what to do ???

Same here with 2.0.11.



No clue what’s happening.

I’ll submit it to the bug tracker since its happening to more than 1 person

Your answer lies in this statement …

[QUOTE]I didn’t fill anything in and clicked “Register” at the bottom …[/QUOTE]



The php command “foreach()” expects to be passed an array …



If a single variable or non-defined variable is passed to foreach, it will throw the exact message shown in the example and described earlier in this thread.



(Most common issues with this is passing a non-array value or one that doesn’t exist yet)



I have not stopped to look at this in any significant detail other than glancing at what you said in passing but just based on your comments and seeing the site example from this thread, I suspect that the code isn’t pre-initializing the array or checking first that the array actually has valid values in it before passing it on to the foreach() loop in the script code.



Perhaps this is meant to be handled by the Javascript / AJAX checks though to be completely thorough, I would run sanity checks against all variables and array data before making use of any of those values in any form anywhere in the script code which would also include pre-checks to make sure the variables exist and the arrays are actually arrays, constants are constants, etc

Spiral, you should give yourself and your paranoia brake and run a security check against your brain!



This error happens before anything is submitted. It’s enough to click on the link to Register and not when submitting empty fields.



Will you start again about 777 and other rubbish? What about you hacking my website? Are you ready for it? It’s a very well paid job if you get into it. You didn’t even reply to your own thread where you were misleading people about security issues and making yourself a security expert. Start contributing to this forum or be gone for good.

I have just done a new installation of CS Cart and when testing the Registar option of the site, I get the same message.



Warning: Invalid argument supplied for foreach() in /home/totalima/public_html/shop/controllers/common/profiles.post.php on line 235



Please Help…



Thanks

David

This occurs only when the General setting “Allow customer to signup for user group” is unchecked. There is a fix provided in bug #1544:

[url]http://forum.cs-cart.com/vbugs.php?do=view&vbug_id=1544[/url]



Bob

Got it… thanks Bob

[quote name=‘jobosales’]This occurs only when the General setting “Allow customer to signup for user group” is unchecked. There is a fix provided in bug #1544:

[url]http://forum.cs-cart.com/vbugs.php?do=view&vbug_id=1544[/url]



Bob[/QUOTE]



Thank you Bob. Much appreciated. I owe you another big one. [bottle?]