Login in Joomla 1.5 through curl
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);
Thanks for that awesome posting. It saved MUCH time
Would using something like this allow an RSS reader to load Joomla 2.5 RSS feeds that are not “Public”? The reader would need to use something like: http://user:pass@joomlawebsitedomain/rssfeed
Joomla doesn’t seem to natively support protected RSS feeds. Any thoughts?
That is a great tip particularly to those fresh to the blogosphere.
Brief but very accurate information… Appreciate your sharing this one.
A must read post!