This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » Symfony sessions/cookies
Symfony sessions/cookies [message #41158] Fri, 07 December 2007 21:54 Go to next message
Whosrodney  is currently offline Whosrodney
Messages: 12
Registered: September 2007
Junior Member
Hi all,

I've got a question about how symfony stores its session variables.

What I'm trying to do is unify the login systems of 2 different apps, one of which is a symfony app and the other is an existing PHP app.

Currently, the existing app relies on setting a PHP session variable '_user'. So if $_SESSION['user'] is set, then that user is logged in on the existing app.

My idea for unifying the login systems is as follows:
1) For going from the existing app to the symfony app, I was going to create a filter which checks for $_SESSION['user']. If found, the symfony app logs the user in with my myUser class.
2) For going from the symfony app to the existing app, I was going to set $_SESSION['uid'] in my myUser class, so that the user would then be logged in to both apps.

However, my plan did not work because apparently the two apps have different PHP sessions. In looking at the cookies, it appears the 'symfony' cookie is subdomain specific (i.e. symfony.example.com), while the 'PHPSESSID' cookie is domain specific (i.e. example.com).

So under my understanding/guesswork, one solution would be to have symfony use the domain-wide 'PHPSESSID' cookie. How would I go about doing this?

As I said I'm not well-versed in session/cookie management, so if anybody knows of a more elegant solution, please let me know Smile

Thanks
Re: Symfony sessions/cookies [message #41271 is a reply to message #41158 ] Mon, 10 December 2007 04:12 Go to previous messageGo to next message
Whosrodney  is currently offline Whosrodney
Messages: 12
Registered: September 2007
Junior Member
Anybody?
Re: Symfony sessions/cookies [message #41274 is a reply to message #41158 ] Mon, 10 December 2007 05:57 Go to previous messageGo to next message
slkaufm  is currently offline slkaufm
Messages: 6
Registered: March 2007
Location: Tokyo, JP
Junior Member
If both apps can work off of a subdomain (even www is OK), then something you can try doing is changing the cookies so that they aren't subdomain specific anymore. That way, you can read in the session values in your non-symfony app, and vice versa.

Add in the following line to your Symfony project's config.php file:

session_set_cookie_params(9600, '/', '.example.com');

9600 is the timeout value.
'.example.com' is the name of the domain, with a leading dot to wildcard it and make it cross subdomains.

You can put a similar line of code in your other PHP app too.

Then, in your non-symfony app, to read in the uid session data, you can do the following:

$session_id = $_COOKIE['symfony'];
session_name('symfony');
session_start();
$params = $_SESSION['symfony/user/sfUser/attributes'];
$params = $params['symfony/user/sfUser/attributes'];
$uid = $params['uid'];

Note that to get this to work, you ALWAYS have to have some kind of subdomain. http://www.example.com will work, but http://example.com won't.

Please let me know if this helps you out.
Re: Symfony sessions/cookies [message #41329 is a reply to message #41274 ] Mon, 10 December 2007 20:22 Go to previous messageGo to next message
Whosrodney  is currently offline Whosrodney
Messages: 12
Registered: September 2007
Junior Member
slkaufm,

Thanks for your reply Smile

I managed to get this working through a solution similar to yours.

In apps/app/config/factories.yml I added

all:
  storage:
    class: sfSessionStorage
    param:
      session_name: example
      session_cookie_domain: example.com



I discovered these attributes by poking around in the SfSessionStorage class.

In my existing project, I set up the cookie as follows:
session_name('example');
$cookieDefaults = session_get_cookie_params();
session_set_cookie_params($cookieDefaults['lifetime'], $cookieDefaults['path'], 'example.com', $cookieDefaults['secure'], $cookieDefaults['httponly'] );

session_start();


I have tested this and it works. Very Happy
Re: Symfony sessions/cookies [message #97457 is a reply to message #41329 ] Thu, 15 April 2010 20:24 Go to previous message
lizarinha  is currently offline lizarinha
Messages: 2
Registered: August 2009
Junior Member
Hi there!

Did you remember if you configure any class or file more? I have been trying to do the same but without results Sad

I have a php application written in php, and a symfony project as a subfolder (in the same domain).

I configured factories.yml and sets the session_name in main application but it seems that the session in symfony is not working.

Thanks in advance!

PS. Sorry about my english

[Updated on: Thu, 15 April 2010 20:24]

Previous Topic:Difference between Action+partial and a Component
Next Topic:propel:data-load fails
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software