Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

How to choose domain and path for session cookie...

<?php
class mySessionStorage extends sfMySQLSessionStorage
{
    public function initialize ($context, $parameters = null)
    {
        session_set_cookie_params ( 90*24*3600 , "/", ".domain.tld" );
        parent::initialize($context, $parameters);
    }
}
?>

Then you have to put in factories.yml

all:
  storage:
    class: mySessionStorage
    param:
      database: ...
      db_table: session
      db_id_col: sess_id
      db_data_col: sess_data
      db_time_col: sess_time
      session_name: ...
by Romain Dorgueil on 2006-05-22, tagged cookie  domain  factory  session  storage 

Comments on this snippet

gravatar icon
#1 Paul Carroll on 2006-05-23 at 01:59

Great Idea. Is there an sf session storage object that isn't MySQL specific? I was thinking about DB abstraction....

gravatar icon
#2 Fabien Potencier on 2006-05-23 at 02:17

Paul: http://www.symfony-project.com/snippets/7

gravatar icon
#3 Paul Carroll on 2006-05-23 at 07:16

Thanks Fabien. I should have read a couple of snippets earlier. :-)

I guess what I was thinking about was a sfSessionStorage which would abstract all of those db specific session storage objects.

gravatar icon
#4 Romain Dorgueil on 2006-05-25 at 03:12

It's not specific to MysqlSessionStorage, you can use any other SessionStorage with this.

gravatar icon
#5 Marco Barberis on 2006-08-20 at 02:01

Hi, this class go in mySessionStorage.class.php in [app]/lib/, right? I extend sfCreoleSessionStorage, modify the factories.yml ( class: mySessionStorage ) but I've got this error:

Fatal error: Call to a member function getNamespaces() on a non-object in /usr/share/php/symfony/debug/sfDebug.class.php on line 98

gravatar icon
#6 Todd Eddy on 2007-01-22 at 07:31

I had the same problem that #5 Marco Barberis had. Attempting this again after a couple months I noticed the error has been fixed now (1.0.0-beta4). Looking through the source I noticed there were some new parameters set up for the session storage class that lets you specify parameters from the factories.yml file, eliminating the need for a custom session class to just set the path.

http://www.symfony-project.com/snippets/snippet/137

You need to create an account or log in to post a comment or rate this snippet.