使用Yii在两个项目中打开会话


Open sessions in two project using Yii

我的处境很复杂。我有两个项目。一个是使用Yii框架设计的,另一个只包含纯PHP代码(我的意思是没有框架)。我想做的是,当用户登录项目时,他/她也应该登录Yii项目。我试图在Yii项目中设置session_id,但没有成功。我使用php头函数重定向用户到Yii项目,以便让用户登录。以下是代码:

PHP项目:

    if (isset($_POST['giris-yap'])) {
        $_POST['eposta']    = $this->cstring->validEmail($_POST['eposta']);
        $_POST['sifre']     = md5($_POST['sifre']);
        if ($_POST['eposta'] != '' && $_POST['sifre'] != '') {
            $params = array(
                'e-posta' => $_POST['eposta'],
                'sifre' => $_POST['sifre']
            );
            $sonuc = $this->loginKendim($params);
            if ($sonuc) {
                 $_SESSION['_utmkendim'] = md5('üyegirişyaptı'.$_POST['eposta']);
                //mya user authentication
                if($_SERVER["REMOTE_ADDR"] = "88.248.192.175")
                {
                    header("Location: https://mya.genel.com/?sessionId=" . $_COOKIE["PHPSESSID"]);
                    exit;
                }
                //end of mya user authentication
                header("Location: https://www.kendim.com/panel");
                exit;
            }
            else
                $this->_kayithata = 1;
        }
        else
            $this->_kayithata = 1;
    }  

Yii项目:

public function beforeAction($action) {
    if(isset($_GET["sessionId"]) && $_GET["sessionId"] != "")
    {
        Yii::app()->session->setSessionID($_GET["sessionId"]);
        session_id($_GET["sessionId"]);
        header("Location: https://www.kendim.com/panel");
        exit;
    }
    # mya wl-api den gelen kullanıcıyı login edelim.
    if(isset($_GET['_MYAU'])){
        $_useruniqueid = Yii::app()->CString->CleanSTR($_GET['_MYAU']); 
        $userlogin = UserslogLogin::model()->findByAttributes(array('login_uniqueid' => $_useruniqueid ));
        if($userlogin){
            $user = UsersAccounts::model()->findByPk($userlogin->user_id, array('select' => 'user_id, user_name, user_email, user_pass'));
            $identity = new UserIdentity($user->user_email, $user->user_pass);
            $identity->id = $user->user_id;
            $identity->name = $user->user_name;
            $identity->username = $user->user_email;
            $duration = 3600*24; //$this->rememberMe ? 3600*24*30 : 1800; // 30 days
            Yii::app()->user->login($identity, $duration);
            Yii::app()->request->redirect('/anasayfa');
            Yii::app()->end();
        }else{
            $action = 'actionError';
            $this->$action();
            Yii::app()->end();             
        }
   }

   # kullanıcı login değilse indexe yönlendir
    if(Yii::app()->user->isGuest){
        $action = 'actionIndex';
        $this->$action();
        Yii::app()->end();   
    }else{
        $this->getuser = UsersAccounts::user();
         Controller::$projectModel =  Projects::loadModel($this->getuser->project_code);
    }

    return parent::beforeAction($action);
}

我不认为问题出在框架上。正如DaSourcerer猜测的那样,问题出在领域上。看看这个以前的帖子:

跨不同域保留会话变量

好的,我找到了解决方案。我忘了使用session_start();。问题解决了。我现在可以在域之间传输会话。