[英]set user id as the current user in Joomla
我有一個userId- $uid
。
我想讓該用戶登錄到joomla中的s / m。
我已經試過了-
$currentUser = new JUser($uid);
$mainframe = JFactory::getApplication('site');
$credentials = array();
$credentials['username'] = $currentUser->username;
$credentials['password'] = $currentUser->password; //this is the hashed password
//perform the login action
$mainframe->login($credentials);
$newuser = JFactory::getUser(); //this doesn't get updated to the new user ($uid) details
如何通過使用uid本身使該用戶成為當前用戶?
更新 :我剛剛發現可以用JUser :: load()加載用戶
試用2
$user = JUser::getInstance($uid);
$user->load($uid); //this should load the new user.
$newuser = JFactory::getUser(); //still i get the anonymous details here
//($newuser->id = 0)
由於有wp_set_current_user($uid);
對於drupal中的wordpress user_load_by_name()
,joomla是否有任何類似的功能? 請幫忙。!!!
謝謝!
有點晚了,但是將來可以對某人有所幫助。 為了設置JFactory :: getUser()的用戶,您需要在會話中進行設置:
JFactory::getSession()->set('user', JFactory::getUser($uid));
我對Joomla並不了解,所以我無法實現它,但這是我的想法:
我記得有一個joomla的切換用戶插件。 我搜索它,發現了這個 。 應該可以移植此代碼,以根據需要通過用戶ID更改用戶。 注意在單擊admin-cp中的鏈接后,它們正在執行其他操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.