2

这是用于登录 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"));

在上述项目中创建此会话后,并在数据库中使用新条目对其进行更新。但仍然无法登录网站。谁能帮我。

谢谢

4

2 回答 2

1

嗨@Devjohn,请检查我的网址,您可以测试您的本地简单如何肥皂访问远程。

你可以在这里找到我对你的问题我认为它可以帮助你

http://phptechnicalgroups.blogspot.in/2012/10/json-return-using-soap-server-and-soap.html

于 2013-11-20T13:08:26.690 回答
1

好的,正如 Brent Friar 发布和 elin 引用的那样,您需要

  • 创建一个新会话并获取关联的令牌
  • 传递用户名、密码和令牌以创建登录会话
  • 获取登录会话的新 cookie 值
  • 将 cookie 传输到浏览器

这是完成所有这些所需的代码:

<?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 网站。运行此脚本后,您应该能够访问该网站并登录。

于 2014-11-26T07:58:22.427 回答