curl login from tutorial
QEliz - October 3, 2008 - 13:35
hi
i am trying to login to drupal through my application using curl, i followed the tutorial i found on drupal
following is d code i am using which will display a form if the user is not logged in, the user name n password will be passed to drupal thriugh curl for login (this file is included within another file)
<?php
//check if user is logged in
//code to be written for this
//else check if username and password is set
//login to Drupal remotely
if(isset($_POST['user_name']) && isset($_POST['password']))
{
$crl = curl_init();
$url = "http://localhost/drupal/";
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_HEADER, 1);
curl_setopt($crl, CURLOPT_COOKIEFILE, "/cookie.txt");
curl_setopt($crl, CURLOPT_COOKIEJAR, "/cookie.txt");
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
// this array will hold the field names and values
$postdata=array(
"edit[name]"=>$_POST['user_name'],
"edit[pass]"=>$_POST['password'],
"edit[form_id]"=>"user-login-form",
"op"=>"Log in"
);
// tell curl we're going to send $postdata as the POST data
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
ob_start();
$result=curl_exec($crl);
ob_end_clean();
$headers = curl_getinfo($crl);
curl_close($crl);
unset($crl);
$redirect = $headers['url'];
echo $redirect;
if ($redirect == $url) {
die("Cannot login.");
}
header("Location: $redirect");
}
//else display form
else
{
?>
<form action="<?php print $_SERVER['PHP_SELF'];?>" method="POST" id="formspace" name="form">
<table border=0>
<tr >
<th colspan=4 style="padding: 3px 0 0 1.5em;">
</th></tr>
<tr>
<td width=85>User Name:</td>
<td><input type="text" name="user_name" size=17 id="user_name"></td>
</tr>
<tr>
<td >Password:</td>
<td><input type="password" name="password" size=17 id="password"></td>
</tr>
<tr>
<td ><input type="submit" value="submit">
</td>
</tr>
<tr>
<td>
<a href="">Register here</a>
</td>
</tr>
</table>
</form>
<?php
} //end else
?>but it always prints "could not login"
can anyone tell me why this is happening
thanx in advance

correction
sorry for the mistake,
it prints "Cannot login." given in the die statement