Just make $group_ids an array, and then in the query where you fetch user data, fetch the usergroup IDs as well, then just use this:
PHP Code:
$membergroupids = explode(',', $rut_row['membergroupids']);
foreach ($membergroupids AS $id)
{
if (in_array($id, $group_ids))
{
$userok = true;
break;
}
else
{
$userok = false;
}
}
if (!in_array($rut_row['usergroupid'], $group_ids) AND !$userok)
{
// user is not allowed
}