diff --git a/library/includes/functions.php b/library/includes/functions.php index ac4f9bf22..92be75480 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -980,7 +980,7 @@ function clean_username($username) * @param bool $allow_guest * @return mixed */ -function get_userdata($u, bool $is_name = false, bool $allow_guest = false) +function get_userdata($u, bool $is_name = false, bool $allow_guest = false, bool $profile_view = false) { if (empty($u)) { return false; @@ -998,6 +998,10 @@ function get_userdata($u, bool $is_name = false, bool $allow_guest = false) $where_sql = "WHERE username = '" . DB()->escape(clean_username($u)) . "'"; } + if ($profile_view) { + $where_sql = "WHERE user_id = " . (int)$u . " OR username = '" . DB()->escape(clean_username($u)) . "'"; + } + $exclude_anon_sql = (!$allow_guest) ? "AND user_id != " . GUEST_UID : ''; $sql = "SELECT * FROM " . BB_USERS . " $where_sql $exclude_anon_sql LIMIT 1"; diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php index 25e824b94..9ecb21c7c 100644 --- a/library/includes/ucp/viewprofile.php +++ b/library/includes/ucp/viewprofile.php @@ -26,7 +26,7 @@ if (!$userdata['session_logged_in']) { } } -if (!$profiledata = get_userdata($_GET[POST_USERS_URL], !is_numeric($_GET[POST_USERS_URL]))) { +if (!$profiledata = get_userdata($_GET[POST_USERS_URL], profile_view: true)) { bb_die($lang['NO_USER_ID_SPECIFIED']); }