Joomla 3身份验证以访问PHP中的外部应用程序

Joomla 3身份验证以访问PHP中的外部应用程序,php,authentication,joomla,Php,Authentication,Joomla,我发现这个非常有用的脚本用于检查Joomla中的身份验证 有人对我如何做到这一点有什么提示或解决办法吗? 提前谢谢你 有很多方法可以做到这一点!:- 例如,您可以使用此代码创建一个类,并使用一个方法使用硬编码用户信息的参数调用它 然而,我认为有一个更好的方法来做到这一点。你不需要装上整个Joomla!验证用户名和密码的框架。乔姆拉!使用默认PHP函数password\u hash和password\u verify。您可以做的是: 使用$\u POST或其他工具收集登录表单的用户信息 对Joom

我发现这个非常有用的脚本用于检查Joomla中的身份验证

有人对我如何做到这一点有什么提示或解决办法吗?
提前谢谢你

有很多方法可以做到这一点!:- 例如,您可以使用此代码创建一个类,并使用一个方法使用硬编码用户信息的参数调用它

然而,我认为有一个更好的方法来做到这一点。你不需要装上整个Joomla!验证用户名和密码的框架。乔姆拉!使用默认PHP函数password\u hash和password\u verify。您可以做的是:

使用$\u POST或其他工具收集登录表单的用户信息 对Joomla执行select查询!users表以获取用户名和密码。例如,从_用户中选择用户名、密码,其中用户名='…' 验证收到的密码\u验证$\u POST['password'],$data['password']。如果正确,则用户登录成功,如果不正确,则返回消息。 有关更多信息,请参阅:

您可能想问自己的另一件事是:我真的需要一个与Joomla!使用相同凭据的独立应用程序吗!。如果应用程序是可以集成到Joomla中的东西!您还可以创建自己的组件。在某些情况下,这样更好


编辑:我忘了一个重要的注意事项。这仅在密码是使用passu散列生成的情况下有效。因此,如果网站因为旧的PHP版本而无法使用此功能,请更新您的内容!!!,md5和salt用作后备。在这种情况下,密码验证将不起作用。

最终我可以得到我想要的。 我保留了剧本的前半部分:

<?php
/**
 * Joomla! External authentication script
 *
 * @author vdespa
 * Version 1.0
 *
 * Code adapted from /index.php
 *
 * @package    Joomla.Site
 *
 * @copyright  Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
if (version_compare(PHP_VERSION, '5.3.1', '<'))
{
    die('Your host needs to use PHP 5.3.1 or higher to run this version of Joomla!');
}
/**
 * Constant that is checked in included files to prevent direct access.
 * define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
 */
define('_JEXEC', 1);
if (file_exists(__DIR__ . '/defines.php'))
{
    include_once __DIR__ . '/defines.php';
}
if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', __DIR__);
    require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
// Instantiate the application.
$app = JFactory::getApplication('site');
?>

并在我的应用程序中恢复用户ID JFactory::getUser->ID。然后,我必须从这个ID$\u userID=JFactory::getUser->ID创建变量。

感谢您花时间回答我的问题。事实上,我不希望用户登录两次,一次在joomla上,一次在应用程序上。我想保持我的域和子域之间的身份验证。
// Hardcoded for now
$credentials['username'] = 'adam';
$credentials['password'] = 'adam';
<?php
/**
 * Joomla! External authentication script
 *
 * @author vdespa
 * Version 1.0
 *
 * Code adapted from /index.php
 *
 * @package    Joomla.Site
 *
 * @copyright  Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
if (version_compare(PHP_VERSION, '5.3.1', '<'))
{
    die('Your host needs to use PHP 5.3.1 or higher to run this version of Joomla!');
}
/**
 * Constant that is checked in included files to prevent direct access.
 * define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
 */
define('_JEXEC', 1);
if (file_exists(__DIR__ . '/defines.php'))
{
    include_once __DIR__ . '/defines.php';
}
if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', __DIR__);
    require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
// Instantiate the application.
$app = JFactory::getApplication('site');
?>