/** * 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; }
/** * 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; }
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_user_table = config_get('mantis_user_table'); $t_cookie_string = auth_get_current_user_cookie(); # @@@ error with an error saying they aren't logged in? # Or redirect to the login page maybe? $c_cookie_string = db_prepare_string($t_cookie_string); $query = "SELECT id\r\n\t\t\t\t FROM {$t_user_table}\r\n\t\t\t\t WHERE cookie_string='{$c_cookie_string}'"; $result = db_query($query); # 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(); # never returns return false; } $t_user_id = (int) db_result($result); $g_cache_current_user_id = $t_user_id; return $t_user_id; }