这是用于登录joomla网站的文件。
// a super-stripped down 2-leg oauth server/client example
function getLogin($userid, $psswrd) {
$app = JFactory::getApplication();
jimport('joomla.user.authentication');
jimport('joomla.session.session');
$auth = &JAuthentication::getInstance();
$session = &JFactory::getSession();
$session->set('name', "value");
$ssn_name = $session->get('name');
$sessionDetails = array(
'State' => $session->getState(),
'Expire' => session->getExpire(),
'Token' => $session->getToken(),
'FormToken' => $session->getFormToken(),
'Name' => $session->getName(),
'Id' => $session->getId(),
'getStores' => $session->getStores(),
'isNew' => $session->isNew());
$username = $userid;
$password = $psswrd;
$credentials = array(
'username' => $username,
'password' => $password);
$options = array();
$response = $auth->authenticate($credentials, $options);
if ($response->status == JAUTHENTICATE_STATUS_SUCCESS) {
$response->status = true;
$sessionDetails['loginStatus'] = $loginStatus = $app->login($credentials, $options);
return $sessionDetails;
}
else {
$response->status = false;
return 'testFalse';
}
}
现在我们通过
使用localhost来调用它$client = new nusoap_client("http://domain-name/site-name/nusoap/remoteLogin.php");
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$result = $client->call("getLogin", array(
"userid" => "admin",
"password" => "test"));
在上述项目中创建此会话并使用新条目在数据库中更新它。但仍然没有登录网站。 任何人都可以帮助我。
由于
答案 0 :(得分:1)
您好@Devjohn请检查我的网址,您可以测试您当地的简单肥皂访问遥控器。
你可以在这里找到我的问题,我觉得它可以帮到你
http://phptechnicalgroups.blogspot.in/2012/10/json-return-using-soap-server-and-soap.html
答案 1 :(得分:1)
好的,正如Brent Friar和elin所说,你需要
以下是完成所有这些所需的代码:
<?php
$uname = $_POST['username'];
$upswd = $_POST['password'];
$url = "http://joomla website.com";
$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_COOKIESESSION, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('./cookie.txt'));
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('./cookie.txt'));
curl_setopt($ch, CURLOPT_HEADER, TRUE );
$ret = curl_exec($ch);
if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)) {
preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof);
}
// POST fields
$postfields = array();
$postfields['username'] = urlencode($uname);
$postfields['passwd'] = urlencode($upswd);
$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 logged in cookie and pass it to the browser
preg_match('/^Set-Cookie: (.*?);/m', $ret, $m);
$cookie=explode('=',$m[1]);
setcookie($cookie[0], $cookie[1]);
?>
只要脚本中使用的URL在页面上有登录表单,这应该适用于任何Joomla网站。运行此脚本后,您应该能够访问该网站并登录。