[英]Allow Login from Different Domain having user login details on a single database of one particular domain - Joomla 1.5
[英]Create 2 cookies in the joomla 1.5 user login
我在joomla 1.5.26网站上遇到问题,该网站与外部数据库进行通信以处理用户和服务,为了进行通信,我必须创建3个cookie,我们可以使用chrome的EditThisCookie在常规URL中查看它在该站点的公共位置,我已经完成了在index.php中使用一行代码smthng这样的操作
// create cookie
setCookie('cookie_one', 'value_of_cookie_one' , 0, '/', '.mysite.com');
现在我的问题是,我想在前端登录时注册一个注册用户,以便在他/她登录后立即创建2个cookie,一个可以说拥有用户名,另一个可以说是会话的session_id
所以在onLoginUser函数上的/plugins/user/joomla.php中,我添加了以下代码,但是在用户登录后我得到了一个空白页面,当然,使用chrome的EditThisCookie时看不到任何cookie。 onLoginUser就像那样,但我不知道这是我的错...任何帮助将是不胜感激的家伙...
function onLoginUser($user, $options = array())
{
$instance =& $this->_getUser($user, $options);
if ($instance instanceof Exception) {
return false;
}
// If the user is blocked, redirect with an error
if ($instance->get('block') == 1) {
return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_NOLOGIN_BLOCKED'));
}
//Authorise the user based on the group information
if(!isset($options['group'])) {
$options['group'] = 'USERS';
}
// Chek the user can login.
$result = $instance->authorise($options['action']);
if (!$result) {
JError::raiseWarning(401, JText::_('JERROR_LOGIN_DENIED'));
return false;
}
//Mark the user as logged in
$instance->set( 'guest', 0);
// Register the needed session variables
$session =& JFactory::getSession();
$session->set('user', $instance);
$db = JFactory::getDBO();
// Check to see the the session already exists.
$app = JFactory::getApplication();
$app->checkSession();
// Update the user related fields for the Joomla sessions table.
$db->setQuery(
'UPDATE '.$db->quoteName('#__session') .
' SET '.$db->quoteName('guest').' = '.$db->quote($instance->get('guest')).',' .
' '.$db->quoteName('username').' = '.$db->quote($instance->get('username')).',' .
' '.$db->quoteName('userid').' = '.(int) $instance->get('id') .
' WHERE '.$db->quoteName('session_id').' = '.$db->quote($session->getId())
);
$db->query();
// Hit the user last visit field
$instance->setLastVisit();
/* ------------------------------------------------------------------------------ */
//Make sure we are in the frontend
if ($app->isSite())
{
// Initialise variables.
$url = $this->params->get('url', JURI::base()) . "?currenturl=" . JURI::base();
$cookie_one = 'value_of_cookie_one';
$cookie_domain = '.mysite.com';
$expire = (time() + 720);
setCookie('ooo_username', $instance->get('username'), $expire, '/', $cookie_domain);
setCookie('ooo_municipality_id', $cookie_one, $expire, '/', $cookie_domain);
setCookie('ooo_session_id', $session->getId(), $expire, '/', $cookie_domain);
// Tell ME the user is logged in
if($this->params->get('ooo_redirection', 0) == 1) {
$app->redirect($url);
}
}
/* ------------------------------------------------------------------------------ */
return true;
}
任何帮助将非常感谢你们谢谢!!!!
在return true
之前,我使用以下方法修复了该问题:
$session = JFactory::getSession();
$instance =& JFactory::getUser();
$instance->get('username');
$cookie_domain = '.mysite.gr';
$expire = (time() + 720);
setCookie('cookie_username', $instance->get('username'), $expire, '/', $cookie_domain);
setCookie('cookie_session_id', $session->getId(), $expire, '/', $cookie_domain);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.