Using CURL to log into JOOMLA
Posted: Thu Sep 03, 2009 12:48 pm
WHY WONT THIS WORK
Code: Select all
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://offers.com.my/");
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, COOKIE_JAR, 'supercookies.txt');
curl_setopt($ch, COOKIE_FILE, 'supercookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
$page = curl_exec($ch);
curl_close($ch);
// Finish Curl Request 1
$find = '<input type="hidden" name="return" value="';
$explode1 = explode($find, $page);
$explode2 = explode('"', $explode1[1]);
$find2 = '<input type="hidden" name="';
$explode1 = explode($find2, $explode1[1]);
$explode1 = explode('"', $explode1[1]);
$string = 'username=[USERNAME]&passwd=[PASSWORD]&remember=yes&Submit=Login&option=com_user&task=login&return='.$explode2[0].'&'.$explode1[0].'=1';
// Prepare Post Curl Request 2
// The previous portion of the script grabs the two hidden variables...
$url2 = 'http://offers.com.my/index.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_REFERER, "http://offers.com.my/");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, COOKIE_JAR, 'supercookies.txt');
curl_setopt($ch, COOKIE_FILE, 'supercookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_exec($ch);
curl_close($ch);