Using user_load() and user_save() to change the status of a logged out user I'm fairly new to Drupal, and I am currently working on a Drupal user registration mechanism that involves authentication on a different website.
The flow is as follows:
- A user registers on a Drupal user/register form. Using user_register_submit() I set the the user's status to blocked.
- After registering, the user is being redirected to a different website where he is required to log in. In that redirect, I pass the newly registered Drupal username as a parameter. If the login on that external site is successful, I'd like to redirect the user back to a .php page on the Drupal site (also sending back the username parameter via POST), and then change the status of that user to Active.

In order to achieve that, I've tried using the following code in a page called auth.php I placed under my theme's root directory. This code is failing:

&lt;?php
    $username = $_POST['user'];
    $user_to_activate = user_load(array('name' =&gt; $username));
    user_save($user_to_activate, array('status' =&gt; 1);
?&gt;


After stumbling upon this http://drupal.org/node/820506, I realized core functions (such as user_load() and user_save() from the user.module) should be available from other modules. So I'd like to put my code inside a custom module, thing is I don't know in which function should I put it. Also, I wouldn't want this module to be called on every page load, only when being redirected from the external website I mentioned in the first comment.

Could someone offer some guidance?
In order to achieve that, I've tried
  using the following code in a page
  called auth.php I placed under my
  theme's root directory.


Normally in Drupal you don't create php files which are called externally. This can be done in some very rare cases. But most of the time you would define a menu callback in a module and have that call a function which you put your code in.

One of the issues that you have found is that Drupal is not bootstrapped from a generic PHP file. 

It is fairly straightforward to do this.


Create a module, with a .module file and a .info file.
Turn on this module via the admin interface.
In your module implement hook_menu() and provide a path to be called, in your example this could be 'mymodule/auth'.
Create a function which will be called when your menu hook is fired. 


There is a more in-depth tutorial here.