How to create a user programmatically in drupal5 (simple version without profile fields)

Posted by: 
Dominique De Cooman

function create_users() {
  $username = 'your_username';                  
  $password = 'your_password';
  $contact = 0;//set to 1 to enable the users personal contact form
 
  $email = '<a href="mailto:your_email@your_domain.com">your_email@your_domain.com</a>'
 
  //optional: create a role and fill in the $rid
  //$roles[$rid] = 'your_role'; 
 
    $account = array(
    'name' => $username,
    'pass' => $password,
    'mail' => $email,
    'init' => $email,
    'timezone' => '-18000',
    'status' => 1,
    'roles' => $roles,
    'contact' => $contact
  );
 
  $account['access'] = time();
  $account['login'] = time();
 
  $account = user_save('', $account);             
}

Add new comment