在joomla 1.5用户登录中创建2个cookie


Create 2 cookies in the joomla 1.5 user login

我有一个joomla 1.5.26网站的问题,该网站与外部数据库通信,以处理用户和服务,为了进行通信,我必须创建3个cookie,其中一个我们可以在正常的url中使用铬的EditThisCookie查看它,我在index.php中使用了一行类似的代码smthng

 // create cookie 
 setCookie('cookie_one', 'value_of_cookie_one' , 0, '/', '.mysite.com');

现在我的问题是,当一个注册用户登录时,我想在前端创建2个cookie,只要他/她登录,一个是用户名,另一个是会话的session_id

因此,在onLogiUser函数的/plugins/user/joomla.php中,我添加了以下代码,但在用户登录后,我得到了一个空白页面,当然,使用chrome的EditThisCookie没有看到cookie。。我在函数onLogiUser中的代码是这样的,但我不知道是我的错误。。。如果有任何帮助,我们将不胜感激。。。

  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);