Source of file SessionCheck.php
Size: 1,760 Bytes - Last Modified: 2021-12-23T10:30:03+00:00
/var/www/docs.ssmods.com/process/src/src/Checks/SessionCheck.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <?php namespace SilverStripe\EnvironmentCheck\Checks; use Psr\Http\Message\ResponseInterface; use SilverStripe\EnvironmentCheck\Traits\Fetcher; use SilverStripe\EnvironmentCheck\EnvironmentCheck; /** * Check that a given URL does not generate a session. * * @author Adrian Humphreys * @package environmentcheck */ class SessionCheck implements EnvironmentCheck { use Fetcher; /** * Set up check with URL * * @param string $url The route, excluding the domain * @inheritdoc */ public function __construct($url = '') { $this->setURL($url); } /** * Check that the response for URL does not create a session * * @return array */ public function check() { $response = $this->client->get($this->getURL()); $cookie = $this->getCookie($response); $fullURL = $this->getURL(); 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) { $result = null; $cookies = $response->getHeader('Set-Cookie'); foreach ($cookies as $cookie) { if (strpos($cookie, 'SESSID') !== false) { $result = $cookie; } } return $result; } } |