Skip to content

Instantly share code, notes, and snippets.

@eugene-ilyin
Created August 3, 2015 09:30
Show Gist options
  • Save eugene-ilyin/0bd4e7aff569903b4bd6 to your computer and use it in GitHub Desktop.
Save eugene-ilyin/0bd4e7aff569903b4bd6 to your computer and use it in GitHub Desktop.
Login programmatically
<?php
/**
* Drupal 7.
*/
$user_obj = user_load(1);
$form_state = array();
$form_state['uid'] = $user_obj->uid;
user_login_submit(array(), $form_state);
/**
* Drupal 6.
*/
$user_obj = user_load(170);
$state = array();
$state['values']['uid'] = $user_obj->uid;
$state['values']['name'] = $user_obj->name;
// Valid login.
global $user;
$user = $user_obj;
user_authenticate_finalize($state['values']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment