I have an external website (not made whith yii) which manage all my user, their profile and their rights for several website.
So an user can Log in once for several website.
Now, when the user log in, he is redirect to my new yii website and the user data is stored in the session.
But with my yii app, I can’t retrieve these informations. (it works for other applications which didn’t use yii). So I guess I don’t have any problem with my authentification website.
Question :
So is it possible to get session data from an other website to a yii website? and how?
Are you getting session data from login site to non-Yii sites? Are you using PHP in the non-Yii sites? Chris Brickhouse has a series of postings about cooking your own Yii auth… anyway it had a function that could log a user on without a password. I have posted the link on here before.
I just noticed it should have been: How are you getting the session data? If you already know how to get session data from one site to the other, then just do the same and set the Yii session data as needed in the authenticatedUser action.
Backhouse site: I think the function I was refering to was in part 4, near the bottom.
Another idea: Can you modify the php site? If so you could JsonEncode to session information and POST it to the Yii site action for authenticated login.
In my other website I just take my informations in
$_SESSION['user']
the informations are in the session after the redirection. But in my yii website, there is nothing.
this is what I did :
My site controller : (I took this from the login action of the demo)
$this->_identity=null;
//Login
if($this->_identity===null)
{
//$this->_identity=new UserIdentity('user','password');
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
$userLogged = true;
}
else
$userLogged = false;
if($userLogged==true)
{
Yii::app()->session['idPers']=2;
$this->render('index');
}
else
{
$this->redirect('http://MyAuthentificationWebSite.com/TheWebsiteWhereIComeFrom');
//after the auth, we will be redirect to this yii website.
}
So, afetr the logIn on the other site, we come back in this action and we are goind to the UserIdentity->authenticate Action where there is :
public function authenticate()
{
if(isset($_SESSION))
{
var_dump('1');
var_dump($_SESSION);
}
else
{
if(isset(Yii::app()->session))
{
var_dump('2');
var_dump(Yii::app()->session);
}
else
{
var_dump("No Session./..");
}
}
/* If there are informations in session about the user, I have to say to the website that the user is logged in.*/
}
whith the var_dump, I check, what I have in session : this is the result :
I don’t think Yii clears the session data, it probably generates it’s own session_id.
In this thread, it sounded like you where able to get the information you wanted from one php site to another php site. That is what I was asking about. If true you should be able to do the same with authenticatedUser() function that Chris talks about.
Another question is if the php site/Yii site are on the same server? Where is session data physically saved in the php-site? Is it the same as the Yii-site. I believe session data can be saved in a db, purhaps you could save into db in one site, pass the session_id to the other site, and load the data from the db there.
and as I said, in the authenticatedUser() function, I tried to do the same things as I did in the other website, so I tried to get informations from the session, but I don’t have anything…
chris tutorial explain how to retrieve user informations from a database, so in the authentification function I’m looking for my user information in the session without any success.
Yes there are both on the same server.
I have this in my php info on the server : session.save_path : c:/temp
I guess, yes, unless if yii store his sesion data in his own folder?
I just tried to add this in my config/main.php in the components array but this didn’t change anything.
I’ll try to send the sessionId to my auth site, my auth site could maybe create the “same” session and then yii could maybe retrieve informations. I’ll try that and will say if it is working or not.
If I go in an other direction, the authentification website could perhaps write something in a db if someone log in with the username/website/date/rights/role… and then in my yii website I could see if there is a new record in the DB, But if 2 users tried to log in at the same time, I guess I have nothing to be sure which record I have to take. (Seems to be a really bad solution)
And other option is to create a little webapp of my authentifiation website, and add it to my yii website, so I could store information directly in the yii session…
Anyway, even if tehre are other solutions, I’m pretty sure it is possible to pass data between php website to yii website so I prefer try to find this solution