Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在joomla 1.5用户登录中创建2个cookie_Php_Login_Joomla1.5 - Fatal编程技术网

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

Php 在joomla 1.5用户登录中创建2个cookie,php,login,joomla1.5,Php,Login,Joomla1.5,我与joomla 1.5.26网站有问题。该网站与外部数据库进行通信,以处理用户和服务,为了进行通信,我必须创建3个cookie,我们可以在正常的url中使用我在index.php中使用的chrome公共站点的EditThisCookie查看它,使用一行类似的代码smthng // create cookie setCookie('cookie_one', 'value_of_cookie_one' , 0, '/', '.mysite.com'); 现在我的问题是,当注册用户登录时,我

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

 // create cookie 
 setCookie('cookie_one', 'value_of_cookie_one' , 0, '/', '.mysite.com');
现在我的问题是,当注册用户登录时,我希望在前端在他/她登录后立即创建两个cookie,一个是用户名,另一个是会话的会话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;
}

非常感谢你们的帮助,谢谢

在返回true之前,我使用以下方法修复了它:


不要使用Joomla!1.5,它已经过时,不再受支持。
    $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);