Skip to content

Instantly share code, notes, and snippets.

@tareko
Last active May 16, 2016 05:37
Show Gist options
  • Save tareko/b2140b578b5bfff1f80aa76fced7ccaf to your computer and use it in GitHub Desktop.
Save tareko/b2140b578b5bfff1f80aa76fced7ccaf to your computer and use it in GitHub Desktop.
Attempt to bootstrap Drupal
<?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://mysite.com/';
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'mydb',
'username' => 'myuser',
'password' => 'mypass',
'host' => 'localhost',
'port' => '3306',
);
$db_url['default'] = 'mysql://myuser:mypass@localhost:3306/mydb';
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment