2013-11-25 41 views
0

我處於複雜的情況。我有兩個項目。一個是使用Yii Framework設計的,另一個只包含純PHP代碼(我的意思是沒有框架)。我想要做的是,當用戶登錄項目時,他/她也應該登錄Yii項目。我試圖在Yii項目中設置session_id,但沒有奏效。我使用PHP的頭功能,以Yii的項目,爲了讓用戶登錄重定向用戶這裏是代碼:使用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); 
} 
+0

你的應用程序位於完全不同的域名'kendim.com'和'genel.com',對吧? – DaSourcerer

+0

是的,你是對的 –

回答

0

好,我找到了解決辦法。我忘記了使用session_start();.問題解決了。我現在可以在域之間傳輸會話。