diff --git a/config/vufind/config.ini b/config/vufind/config.ini index fff872deaaae94b42ee2456aecfe3e07676362f9..59b9e5b8f1afdedc5ca67a8fc9ff0365b4d8c264 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -159,6 +159,9 @@ lifetime = 3600 ; Session lasts for 1 hour ; Set the domain used for cookies (sometimes useful for sharing the cookies across ; subdomains); by default, cookies will be restricted to the current hostname. ;domain = ".example.edu" +; This sets the session cookie's name. Only needed if you use session sharing over +; multiple subdomains (see domain setting above) and you have multiple PHP apps. +;session_name = VUFIND_SESSION ; Please set the ILS that VuFind will interact with. ; diff --git a/module/VuFind/src/VuFind/Cookie/CookieManager.php b/module/VuFind/src/VuFind/Cookie/CookieManager.php index 05a9d0008f0e29e2b4e854eef0a32dd7dd697ccc..66d95e0c99ea2ba659514a16f02cfb048d3fae04 100644 --- a/module/VuFind/src/VuFind/Cookie/CookieManager.php +++ b/module/VuFind/src/VuFind/Cookie/CookieManager.php @@ -59,21 +59,31 @@ class CookieManager */ protected $secure; + /** + * The name of the session cookie + * + * @var string + */ + protected $sessionName; + /** * Constructor * - * @param array $cookies Cookie array to manipulate (e.g. $_COOKIE) - * @param string $path Cookie base path (default = /) - * @param string $domain Cookie domain - * @param bool $secure Are cookies secure only? (default = false) + * @param array $cookies Cookie array to manipulate (e.g. $_COOKIE) + * @param string $path Cookie base path (default = /) + * @param string $domain Cookie domain + * @param bool $secure Are cookies secure only? (default = false) + * @param string $sessionName Session cookie name (if null defaults to PHP + * settings) */ public function __construct($cookies, $path = '/', $domain = null, - $secure = false + $secure = false, $sessionName = null ) { $this->cookies = $cookies; $this->path = $path; $this->domain = $domain; $this->secure = $secure; + $this->sessionName = $sessionName; } /** @@ -116,6 +126,16 @@ class CookieManager return $this->secure; } + /** + * Get the name of the cookie + * + * @return mixed + */ + public function getSessionName() + { + return $this->sessionName; + } + /** * Support method for setGlobalCookie -- proxy PHP's setcookie() function * for compatibility with unit testing. diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index d406c6a583be37062997b00458649f37f14252eb..39a46be00f35df6af203d1d6c156e5fd1b65f5c3 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -215,7 +215,12 @@ class Factory $domain = isset($config->Cookies->domain) ? $config->Cookies->domain : null; - return new \VuFind\Cookie\CookieManager($_COOKIE, $path, $domain, $secure); + $session_name = isset($config->Cookies->session_name) + ? $config->Cookies->session_name + : null; + return new \VuFind\Cookie\CookieManager( + $_COOKIE, $path, $domain, $secure, $session_name + ); } /** diff --git a/module/VuFind/src/VuFind/Session/ManagerFactory.php b/module/VuFind/src/VuFind/Session/ManagerFactory.php index 4210d729bd32c02c2e7b46f29c256cec98f865a2..db2c4de87114998e67075ec46b1ddef8ab4f5a43 100644 --- a/module/VuFind/src/VuFind/Session/ManagerFactory.php +++ b/module/VuFind/src/VuFind/Session/ManagerFactory.php @@ -56,10 +56,17 @@ class ManagerFactory implements \Zend\ServiceManager\FactoryInterface 'cookie_path' => $cookieManager->getPath(), 'cookie_secure' => $cookieManager->isSecure() ]; + $domain = $cookieManager->getDomain(); if (!empty($domain)) { $options['cookie_domain'] = $domain; } + + $name = $cookieManager->getSessionName(); + if (!empty($name)) { + $options['name'] = $name; + } + return $options; }