1
我想通過CURL從外部鏈接登錄到Joomla 3。從網上的一些調查結果後,我獲得此代碼一些調整:PHP + CURL + JOOMLA
<?php
$uname = "admin";
$upswd = "admin";
$url = "http://localhost/joomla3/en/component/users";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$results = curl_exec($ch);
preg_match_all("(<input type=\"hidden\" name=\"return\" value=\"(.*)\" />)siU", $results, $matches1);
preg_match_all("(<input type=\"hidden\" name=\"(.*)\" value=\"1\" />(.*)</fieldset>)iU", $results, $matches2);
var_dump($matches1[1][0]);
var_dump($matches2[1][0]);
// POST fields
$postfields = array();
$postfields['lang'] = 'en';
$postfields['option'] = 'com_users';
$postfields['view'] = 'login';
$postfields['task'] = 'user.login';
$postfields['username'] = urlencode($uname);
$postfields['password'] = urlencode($upswd);
$postfields['return'] = urlencode($matches1[1][0]);
$postfields[urlencode($matches2[1][0])] = '1';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
print_r($ret);
?>
我獲得的回報&關鍵,但無法登錄。哪裏不對? 謝謝。
您獲得的輸出是什麼? – Raptor
print_r($ ret);什麼都沒有返回(一個空字符串)。 –
curl調試基礎:'curl_error()':http://www.php.net/manual/en/function.curl-error.php – Raptor