我在任何地方都没有找到答案,所以经过一番努力,这里是如何做到这一点:
<?php
# Set username and password
$username = 'NAME';
$password = 'PASSWORD';
# Drupal Bootstrap code
define('DRUPAL_ROOT', '/var/aegir/platforms/drupal_7');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
# My attempt at injecting variables for multisite stuff to fit aegir
$variables['url'] = 'http://example.com/';
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'mydb',
'username' => 'myuser',
'password' => 'mypass',
'host' => 'localhost',
'port' => '3306',
);
$db_url['default'] = 'mysql://sqluser:sqlpass@localhost:3306/sqldb';
drupal_override_server_variables($variables);
# Try to bootstrap
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
# Try to login
$uid = FALSE;
$account = user_load_by_name($username);
if ($account) {
// Allow alternate password hashing schemes.
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
if (user_check_password($password, $account)) {
// Successful authentication.
$uid = $account->uid;
// Update user to new password scheme if needed.
if (user_needs_new_hash($account)) {
user_save($account, array('pass' => $password));
}
}
}
debug($uid);