title: drupal 7 programmatically log user in
body: <p>After having just registered a new account and created a profile how would I log a user in?</p>
  
  <p>I have tried :</p>
  
  <pre><code>global $user;
  $user = user_load($account-&gt;uid);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>global $user;
  $user = user_load(array('mail' =&gt; $_POST['email'], 'pass' =&gt; trim($_POST['password'])));
  </code></pre>
  
  <p>but neither work and the second results in an error about array_flip.</p>