Hi,
Here is a code for loading current logged-in user using Bootstrap full in external PHP file.
function user_load_from_bootstrap($uid = NULL) {
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
$base_url = 'https://'.$_SERVER['HTTP_HOST']; // this will load base url of website
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
return $user;
}
without loading bootstrap and Using Session for current logged in user:
function user_load_from_session($uid = NULL) {
$session_name = session_name();
if (!empty($session_name)) {
if ($uid = db_query("SELECT uid FROM {sessions} WHERE sid = :sid", array(':sid' => $_COOKIE[$session_name]))->fetchColumn()) {
$user = user_load($uid);
return $user;
}
}
}
Hope this may be helpful to for drupal developers.
0 Comment(s)