diff --git a/user/view.php b/user/view.php
index 5f1aad0cc45..64bd305db6d 100644
--- a/user/view.php
+++ b/user/view.php
@@ -35,6 +35,25 @@
$personalprofile = get_string("personalprofile");
$participants = get_string("participants");
+ $groupmode = groupmode($course);
+
+ if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate
+ if ($groupmode == SEPARATEGROUPS) {
+ require_login();
+
+ if (!ismember($USER->groupmember[$course->id], $user->id)) {
+ print_header("$personalprofile: ", "$personalprofile: ",
+ "id\">$course->shortname ->
+ id\">$participants",
+ "", "", true, " ", navmenu($course));
+ print_heading("Sorry, you can't see this user because you are not in his group");
+ print_footer();
+ die;
+ }
+
+ }
+ }
+
if ($course->category) {
print_header("$personalprofile: $fullname", "$personalprofile: $fullname",
"id\">$course->shortname ->