Allow PHP Sessions to Carry Over to Subdomains

keeping sessions alive over subdomains

In your .htaccess you can set your session cookie domain to the base.

php_value session.cookie_domain ".domain-uk.net"

You can also do this inside of your application:

<?php 
session_set_cookie_params(0, '/', '.domain-uk.net');
session_start();
?>

PHP session works on all subdomains

There are several things to take in account while sharing $_SESSION across subdomains.

  1. Are all subdomains on ran by the same server?

    1. If not, then, you will need to share sessions amongst servers, there are several solutions:

      • Use NFS (not recommended)
      • Move SESSION to another storage (Database, Memcache, Redis) (best option imho)
    2. If they are, you may just need to configure your cookie domain using session.cookie_domain ini directive.

  2. Are you running Suhosin, if you do, you may need to disable some security options to allow your session to be decrypted on the others servers.



Related Topics



Leave a reply



Submit