login to magento 1.7 from drupal 7 function custom_user_login($edit, $account) {

  require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";
  global $user;

  umask(0);
  Mage::App('default');
  $session = Mage::getSingleton('customer/session', array('name' =&gt; 'frontend'));
  try {
    $session-&gt;login('alvaro@test.com', 'cec123');

    $session-&gt;setCustomerAsLoggedIn($session-&gt;getCustomer());
  } catch (Exception $e) {
    print_r($e);
    exit;
  }


i am using this set of code from my D7 installation to log-in to magento.But it is not loggin into either D7 or magento.

But when i run this code from a seperate simple php file outside it logs in to magento successfully. what could be the problem.
The function signature is not right, which may be the reason for the code not executing.
See the docs for hook_user_login function.

The parameter $edit is passed by reference and not directly by value. So, the correct definition your function should be,

function custom_user_login(&amp;$edit, $account) {

  // rest of the code goes here (not duplicating).

}


Also make sure, your modules name is custom and it has files custom.info and custom.module in the module directory. And offcourse, enable the module ;-)

Also, to suggest you to look into the session and cookie info (based on your comment), you can put an echo '&lt;pre&gt;';print_r($_COOKIE); echo &lt;/pre&gt; inside your theme's template.php file.
Or simply install the Devel module, and enter dpm($_COOKIE); inside your template.php, to see a nicely formatted result. You'll need to clear the cache to again load the fresh template files.
Similarly, you can print the $_SESSION superglobal to see the session information.