Created
August 3, 2015 09:30
-
-
Save eugene-ilyin/0bd4e7aff569903b4bd6 to your computer and use it in GitHub Desktop.
Login programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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