login programmatically not work according to this  I wrote below code to create temp user and login ,
, user create but it not logged in.
where is problem?

   $user_info = array(
  'name' =&gt; 'temp-payment-'.rand(1,999),
  'pass' =&gt; user_password(),
  'mail' =&gt; 'no@no.com',
  'init' =&gt; 'temp-user-'.rand(1,999),
  'status' =&gt; 1,
  'roles' =&gt; array(DRUPAL_AUTHENTICATED_RID =&gt; TRUE),
                    'access' =&gt; time(),
                    );
  $user = user_save('',$user_info);



  if($user) {
   $GLOBALS['user'] = $user;
    drupal_save_session(TRUE);
    ym($user);
  }
  drupal_goto('/user');
Solution is 

 $form_state['uid'] = $user-&gt;uid;
 user_login_submit(array(), $form_state);


and final code :

$user_info = array(
  'name' =&gt; 'temp-payment-'.rand(1,999),
  'pass' =&gt; user_password(),
  'mail' =&gt; 'no@no.com',
  'init' =&gt; 'temp-user-'.rand(1,999),
  'status' =&gt; 1,
  'roles' =&gt; array(DRUPAL_AUTHENTICATED_RID =&gt; TRUE),
                    'access' =&gt; time(),
                    );
  $user = user_save('',$user_info);
//drupal_save_session(FALSE);
//$loggedin = user_authenticate($user-&gt;name, $user-&gt;pass);
//ym($loggedin);
$form_state['uid'] = $user-&gt;uid;
 user_login_submit(array(), $form_state);
//drupal_save_session(FALSE);
$GLOBALS['user'] = $user;
drupal_save_session(TRUE);
//drupal_goto('/user');


hope be useful for another users,.

This code generate and login to it programmatically