2

How can I programmatically create user in another Drupal site?

The setup: multisite installation, userbase should be partially shared. Both websites have DB credentials setup in the settings.php file so I can query all tables from either site.

The problem: if I use db_set_active() to switch the database to the second site, calling user_save() will invoke all hooks of modules that are installed on the first site, not on the second one. This causes errors if the sites have different modules.

How can I avoid this problem? Any thoughts on workarounds?

Thanks!

1 Answer 1

1

One clean way to do this is using a web service with the services module. You could then expand to being able to create users through javascript or another server without direct access to that database.

It's easy to make your own resources to do exactly what you want.

It comes with native support for core functions, including registering users using the user resource. It's worth mentioning that the maintainers are happing to add new resources that support handling core functionality.

There's also other modules that extend services to provide single sign-on for example.

2
  • Thanks for your reply Helder; I will have a look and let you know if it worked. Aug 6, 2013 at 20:36
  • Checked all possibilities - this is exactly what I was looking for. Thanks again Helder! Aug 7, 2013 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.