我想讓一個腳本以Joomla面板中的管理員身份自動登錄。我使用snoopy進行發佈查詢,並且它的工作正常,但Joomla的響應是安全令牌是錯誤的。我使用JSession::getFormToken()
來獲取令牌,當我回顯它時輸出一個令牌(但可能不是正確的?)。joomla管理員通過php登錄腳本錯誤的令牌
爲什麼我需要那個? 我只想製作一個腳本,授予我管理員權限到我的網站(該腳本將受密碼保護)並自動創建文章,但問題是Joomla中的安全令牌(當前使用版本3.0),這是管理員登錄所需的也用於發佈文章。有沒有更簡單的方法來實現我的想法?
這裏是我使用的腳本(BTW劇本的一篇文章中,我使用directPHP綁定在文章PHP):
<?php include "Snoopy.class.php";
$snoopy = new Snoopy;
$x=JSession::getFormToken();
$submit_url = "http://domain.com/administrator/index.php";
$submit_vars["username"] = "admin";
$submit_vars["passwd"] = "mypassword";
$submit_vars["option"] = "com_login";
$submit_vars["task"] = "login";
$submit_vars["return"] = "aW3kDXgucMhw";
$submit_vars[$x] = "1";
if($snoopy->submit($submit_url,$submit_vars))
{
while(list($key,$val) = each($snoopy->headers))
echo $key.": ".$val."<br>\n";
echo "<p>\n";
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n"; ?>
輸出如下:
0: HTTP/1.1 200 OK
1: Date: Sat, 21 Dec 2013 15:02:53 GMT
2: Server: Apache
3: X-Powered-By: PHP/5.3.28
4: Connection: close
5: Content-Type: text/html
Die Anfrage wurdezurückgewiesen,da der Sicherheitstokenungültigist。 Aktualisieren Sie die Seite und versuchen Sie es erneut。 (意味着查詢被拒絕,因爲安全令牌錯誤)
那麼,如何獲得「正確的」安全令牌或者是否有更簡單的方法來實現我的想法。 在此先感謝。
我也試過這種方法http://stackoverflow.com/questions/19564730/joomla-login-automatically-performed-by-external-php-script-which-is-called-thro?rq=1沒有成功。 – user3125470