url = $url; $this->clientConfig = [ 'base_uri' => Director::absoluteBaseURL(), 'timeout' => 10.0, ]; } /** * Check that the response for URL does not create a session * * @return array */ public function check(): array { $response = $this->fetchResponse($this->url); $cookie = $this->getCookie($response); $fullURL = Controller::join_links(Director::absoluteBaseURL(), $this->url); if ($cookie) { return [ EnvironmentCheck::ERROR, "Sessions are being set for {$fullURL} : Set-Cookie => " . $cookie, ]; } return [ EnvironmentCheck::OK, "Sessions are not being created for {$fullURL} 👍", ]; } /** * Get PHPSESSID or SECSESSID cookie set from the response if it exists. * * @param ResponseInterface $response * @return string|null Cookie contents or null if it doesn't exist */ public function getCookie(ResponseInterface $response): ?string { $result = null; $cookies = $response->getHeader('Set-Cookie'); foreach ($cookies as $cookie) { if (strpos($cookie, 'SESSID') !== false) { $result = $cookie; } } return $result; } }