欢迎各位兄弟 发布技术文章
这里的技术是共享的
1) 第一种方法
drupal6
user.module user_load($user_info = array())
$account = user_load(array('name' => check_plain($name)));
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load/6.x
drupal7 可以通过 user_load_by_name user_load_by_mail 等方法 研究下 user_load_multiple ,调用 user_load_multiple 方法
user_load_multiple
function user_load_by_name($name) {
$users = user_load_multiple(array(), array('name' => $name));
return reset($users);
}
function user_load_by_mail($mail) {
$users = user_load_multiple(array(), array('mail' => $mail));
return reset($users);
}
1) 第二种方法$account = user_load_by_name($user_name); //好像drupal 6 不行
if (user_access('access administration pages', $account)) {
// Do something
}
2) 第
三种方法
function get_uid($username) {
// Function that returns the uid based on the username given
$user = db_fetch_object(db_query("SELECT uid FROM users WHERE name=':username'", array(":username" => $username))); return $user->uid;
}
4) 第四种方法
// Add the user you want to find here $user_to_lookup = 'test';
$users = entity_load('user');
$found_user = null;
foreach ($users as $user)
{
if ($user->name == $user_to_lookup ) {
$found_user = $user;
}
}
|
|