2014-10-10 50 views
0

我有一个joomla 1.5.26站点的问题这个站点与外部数据库进行通信以处理用户和服务,为了沟通我必须创建3个cookie,一个我们在正常的URL使用Chrome的EditThisCookie的网站,我已经做了的市民,用一行代码smthng像在joomla 1.5用户登录创建2个cookie

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

现在我的问题使用在index.php可以看到它,我想在登录用户在登录后立即创建2个cookie的前端,一个让我们说有用户名和第二个会话的session_id

所以在/plugins/user/joomla.php函数onLoginUser我已经添加了下面的代码,但我得到一个空白页后用户登录,当然没有饼干看到使用EditThisCookie的铬..我的代码在功能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; 
} 

任何帮助将非常感激你们谢谢!!!!

+0

不要使用的Joomla! 1.5,已经过时,不再支持。 – 2014-10-10 12:11:59

回答

0

我固定它使用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);