php - Kohana persistant sessions and sub-domains -


I am using database session driver in Kohana v2. For the continuation of the session, Kohana creates a token cookie. This supplement uses cookie cookie configuration.

When I set a session like this:

  $ this-> Session-> Set ('UserID', $ User-> UserID);  

The session variable user ID is available even when the browser is off.

The cookie uses this configuration setting:

  $ Config ['domain'] = '.mydomain.com';  

How can I set up a domain when I set up session variables? Each user has this sub-domain, so it's a dynamic value.

You can find that you are currently in index.php Whether subdomains are bootstrapping process, and then include that variable in the cookie configuration file such as (unchecker):

  $ myDomain = 'mydomain.com'; $ CurrDomain = $ _SERVER ['SERVER_NAME']; $ Subdomain = ''; // If necessary, delete www (substart ($ currDomain, 0, 4) == 'www.') {$ CurrDomain = substr ($ currDomain, 4); $ $ CurrDomainPos = strpos ($ currDomain, $ myDomain); If ($ currDomainPos! == false) {// Prudential investigation, myDomain string should be present ($ currDomainPos! == 0) {// subdomain is found because SERVER_NAME starts with my $$ subdomain = substr ($ currDomain, 0) Does not happen, $ CurrDomainPos); }}  

Then in Cookie Config:

  $ config ['domain'] = "$ subdomain.mydomain.com";  

Comments