Archive

Archive for December, 2011

Login in Joomla 1.5 through curl

December 1, 2011 3 comments

First of all we need three inputs.
$uname = “test”;
$upswd = “123456”;
$url = ‘http://localhost/joomla/index.php?option=com_user&view=login’

//Initialize curl. This is one time curl session no need another session.
$ch = curl_init();

//Try to loging in[Joomla]
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, ‘./cookie.txt’);
curl_setopt($ch, CURLOPT_COOKIEFILE, ‘./cookie.txt’);
curl_setopt($ch, CURLOPT_HEADER, FALSE );
$ret = curl_exec($ch);//access login page
if (!preg_match(‘/name=”([a-zA-z0-9]{32})”/’, $ret, $spoof)) {
preg_match(“/name='([a-zA-z0-9]{32})’/”, $ret, $spoof);
}
// Collecting all POST fields
$postfields = array();
$postfields[‘username’] = $uname;
$postfields[‘passwd’] = $upswd;
$postfields[‘lang’] = ”;
$postfields[‘option’] = ‘com_user’;
$postfields[‘task’] = ‘login’;
$postfields[$spoof[1]] = ‘1’;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);//Get result after login page.
//Close curl and free server recourses.
curl_close($ch);

Categories: Joomla 1.5