I am in a complicated situation. I have two projects. One is designed using Yii Framework, another one includes only pure PHP code (I mean no framework). What I want to do is that, when user logged in the project, he/she should be logged in Yii project either. I tried to set session_id in Yii project, but it didn't work. I am redirecting user by using php header function in order to Yii project in order to let user log in. Here are the codes:
PHP project:
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 Project:
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);
}
I don't think the problem was the framework. The problem are the domains, as DaSourcerer guessed. Take a look at this previous post:
Ok I found the solution. I've forgotten using session_start();. Problem is solved. I can transfer session between domains right now.