我正在尝试制作自己的登录表单以扩展更多字段信息。我尝试将它与我的站点分开构建,因此我将其保存到testlogin.php
基本的 Joomla 主站点目录中。这是我的脚本:
<?php
define('_JEXEC', 1 );
define ('JPATH_BASE', dirname(_FILE_));
define('DS',DIRECTORY_SEPARATOR);
require_once(JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once(JPATH_BASE.DS.'includes'.DS.'framework.php');
require_once(JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'factory.php');
$mainframe =& JFactory::getApplication('site');
$mainframe ->initialise();
$credentials=Array('username' => 'dadanuser', 'password' => 'dadan');
$options=Array('remember' => true);
$mainframe->login($credentials, $options);
//echo $result;
$user =& JFactory::getUser();
echo $user->username;
$session =& JFactory::getSession();
$myUser = $session->set( 'myUser', $user );
?>
我直接运行它,我使用用户名登录:dadanuser,但是当我打开 Joomla 主站点时,我仍然没有登录,也许我必须以正确的方式设置会话?
任何人都可以帮忙吗?