<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://base_drupal_url/drupal7/user/login");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP script');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"name=username&pass=password&form_id=user_login");
ob_start(); //dont print out this output
curl_exec ($ch);