Drupal 获取当前用户信息同样很简单 只需要使用
global $user;
用户信息:
global $user;
$username = $user->name;
$password = $user->pass;
Drupal数据库查询语句:
//数组形式 sql = "select * from {chat_config} where id='1'"; $rs = db_query($sql); $chat_Config = $rs->fetchAssoc();
//对象形式 $roleadmin = db_query("select rid from {role} where name = 'administrator'"); $role = $roleadmin->fetchObject();
Drupal密码验证:
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc'); $usertable = "{users}"; $username_field = "name"; $password_field = "pass"; $email_field = "mail"; $uid_field = "uid";
$username = isset($_GET['username']) ? trim(urldecode($_GET['username'])) : ''; $username = mysql_escape_string($username); $sql = "SELECT " . $username_field ." , ". $password_field . ", ". $email_field . ", ". $uid_field . " FROM " . $usertable . " WHERE ". $username_field . " = '" . str_replace("\\'", "''", $username) . "'"; if($result = db_query($sql)){ if($row = $result->fetchObject()){ if(user_check_password($password,$row)){ //验证成功 }else{ //验证失败 } } }else{ //没有结果 }
Drupal获取当前用户是否为管理员
//需要有用户ID(uid)
$roleadmin = db_query("select rid from {role} where name = 'administrator'");
$role = $roleadmin->fetchObject();
$rolequry = db_query("select * from {users_roles} where uid = '". $row->uid ."' and rid = '". $role->rid ."'");
$roleset = $rolequry->fetchObject();
if(!empty($roleset)){
//是管理员
}else{
//不是管理员
}
(5542)