Home > Backend Development > PHP Tutorial > Joomla3 add an administrator

Joomla3 add an administrator

WBOY
Release: 2016-07-25 08:47:23
Original
1021 people have browsed it
Generally, the user group id is 2 and the administrator group id is 8. Since setting the group id in User Class will also verify whether the current user has the permission to manage the role, so without logging in, you can only set 2 first and then use SQL to change it. 8.
                 
                                                                                                                                                                                                                                                                                                                     


JPluginHelper::importPlugin('user');
$user = new JUser;
    $data = array(
  1. 'name' => 'Admin',
  2. 'username' => 'admin',
  3. 'email' => 'catcat811@hotmail.com',
  4. 'password' => '123456',
  5. 'groups' => array(2),
  6. 'block' => 0
  7. );
  8. $ user->bind($data);
  9. $user->save();
  10. $db = JFactory::getDbo();
  11. $db->setQuery('SELECT id FROM #__users WHERE username='. $db->Quote($data['username']));
  12. $user_id = $db->loadResult();
  13. if($user_id) {
  14. $db->setQuery('UPDATE #__user_usergroup_map SET group_id=8 WHERE user_id='.(int)$user_id);
  15. $db->query();
  16. }
  17. Copy code
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template