Get Data From External Website To Yii

Hi everybody.

Situation :

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?

thanks you very much !

Have a good Day.


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.

You could:

  • logon to site A

  • Redirect to site B //site/authenticatedUser

    • Pass or get session data from site A

    • Place it is Yii Identity.

  • redirect to //site/index.

I’m getting session data from a “non-yii but php website” to a “yii website”.

And my problem is to retrieve the data send by the non yii website in my yii website. (your step 3)

ps : I add the link you’r talking about :–-Part-1/989

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


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=new UserIdentity('user','password');





            	$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days


            	$userLogged = true;



            	$userLogged = false;









//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()
















				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 :

string(1) "2" object(CHttpSession)#18 (5) { ["autoStart"]=> bool(true) ["behaviors"]=> array(0) { } ["_initialized":"CApplicationComponent":private]=> bool(true) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } 

So $_SESSION doesn’t exist, and there is nothing about the user in Yii::app()->session.

I don’t know where I have to go :s

(maybe in the framework, when yii create the session it "unset" the $_session? and so I have to modify that? )

thanks in advance for your time ;)

And have a good day !

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.

yes it’s true, between 2 php site it’s working.

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.

		'session' => array (

				'autoStart' => false,

				'cookieMode' => 'only',

				'savePath' => 'c:/temp',


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 :confused: