/** * Get a user id from their real name * * @param string $p_realname The realname to retrieve data for. * @return array */ function user_get_id_by_realname($p_realname) { global $g_cache_user; if ($t_user = user_search_cache('realname', $p_realname)) { return $t_user['id']; } $t_query = 'SELECT * FROM {user} WHERE realname=' . db_param(); $t_result = db_query($t_query, array($p_realname)); $t_row = db_fetch_array($t_result); if (!$t_row) { return false; } else { user_cache_database_result($t_row); return $t_row['id']; } }
/** * Retrieve user id of current user * @return int user id * @access public */ function auth_get_current_user_id() { global $g_cache_current_user_id; if (null !== $g_cache_current_user_id) { return $g_cache_current_user_id; } $t_cookie_string = auth_get_current_user_cookie(); if ($t_result = user_search_cache('cookie_string', $t_cookie_string)) { $t_user_id = (int) $t_result['id']; $g_cache_current_user_id = $t_user_id; return $t_user_id; } $t_user_table = db_get_table('user'); /** @todo error with an error saying they aren't logged in? Or redirect to the login page maybe? */ $query = "SELECT id\n\t\t\t\t FROM {$t_user_table}\n\t\t\t\t WHERE cookie_string=" . db_param(); $result = db_query_bound($query, array($t_cookie_string)); # The cookie was invalid. Clear the cookie (to allow people to log in again) # and give them an Access Denied message. if (db_num_rows($result) < 1) { auth_clear_cookies(); access_denied(); exit; } $t_user_id = (int) db_result($result); $g_cache_current_user_id = $t_user_id; return $t_user_id; }
/** * Get a user id from their real name * * @param string $p_realname Realname * @return array */ function user_get_id_by_realname($p_realname) { global $g_cache_user; if ($t_user = user_search_cache('realname', $p_realname)) { return $t_user['id']; } $t_user_table = db_get_table('user'); $query = "SELECT * FROM {$t_user_table} WHERE realname=" . db_param(); $result = db_query_bound($query, array($p_realname)); $row = db_fetch_array($result); if (!$row) { return false; } else { user_cache_database_result($row); return $row['id']; } }
/** * Retrieve user id of current user * @return integer user id * @access public */ function auth_get_current_user_id() { global $g_cache_current_user_id; if (null !== $g_cache_current_user_id) { return $g_cache_current_user_id; } $t_cookie_string = auth_get_current_user_cookie(); if ($t_result = user_search_cache('cookie_string', $t_cookie_string)) { $t_user_id = (int) $t_result['id']; current_user_set($t_user_id); return $t_user_id; } # @todo error with an error saying they aren't logged in? Or redirect to the login page maybe? db_param_push(); $t_query = 'SELECT id FROM {user} WHERE cookie_string=' . db_param(); $t_result = db_query($t_query, array($t_cookie_string)); $t_user_id = (int) db_result($t_result); # The cookie was invalid. Clear the cookie (to allow people to log in again) # and give them an Access Denied message. if (!$t_user_id) { auth_clear_cookies(); access_denied(); exit; } current_user_set($t_user_id); return $t_user_id; }