Skip to content

Commit

Permalink
Set the value of the max age for cookie to 30days
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandra Fey committed Oct 27, 2021
1 parent 66edc12 commit b00a866
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Classes/Middleware/RedirectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

/**
* Returns redirect response based on users browser language.
* Sets the cookie for 30 days.
*
* @param ServerRequestInterface $request
* @param string $cookieName
Expand Down Expand Up @@ -187,12 +188,12 @@ function ($language) use ($siteLanguages, $siteLanguagesFallbacks) {

/** @var RedirectResponse $response */
$response = new RedirectResponse($uri, 302);
return $response->withAddedHeader('Set-Cookie', $cookieName . '=' . $matchingSiteLanguage->getLanguageId() . '; Path=/; Max-Age=' . (time()+60*60*24*30));
return $response->withAddedHeader('Set-Cookie', $cookieName . '=' . $matchingSiteLanguage->getLanguageId() . '; Path=/; Max-Age=' . (60*60*24*30));
}

/**
* Returns redirect response based on users IP address. GeoIP2 is used to
* get the country based on the visitors IP address.
* get the country based on the visitors IP address. Sets the cookie for 30 days.
*
* @param ServerRequestInterface $request
* @param string $cookieName
Expand Down Expand Up @@ -261,15 +262,15 @@ function ($siteLanguage) use ($geocodedIsoCode) {

/** @var RedirectResponse $response */
$response = new RedirectResponse($uri, 302);
return $response->withAddedHeader('Set-Cookie', $cookieName . '=' . $matchingSiteLanguage->getLanguageId() . '; Path=/; Max-Age=' . (time()+60*60*24*30));
return $response->withAddedHeader('Set-Cookie', $cookieName . '=' . $matchingSiteLanguage->getLanguageId() . '; Path=/; Max-Age=' . (60*60*24*30));
} catch (\Throwable $e) {
// IP address is not in database. Do not redirect.
return null;
}
}

/**
* Sets cookie with preferred language when user changes language in the frontend.
* Sets cookie with preferred language when user changes language in the frontend for 30 days.
*
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
Expand Down Expand Up @@ -307,7 +308,7 @@ protected function setCookieOnLanguageChange(ServerRequestInterface $request, Re
strpos($refererUri->getPath(), $requestLanguage->getBase()->getPath()) !== 0 ||
($requestLanguage->getBase()->getPath() === '/' && !in_array($requestLanguage->getBase()->getPath(), $siteLanguageBasePaths))
) {
$response = $response->withAddedHeader('Set-Cookie', $cookieName . '=' . $requestLanguage->getLanguageId() . '; Path=/; Max-Age=' . (time()+60*60*24*30));
$response = $response->withAddedHeader('Set-Cookie', $cookieName . '=' . $requestLanguage->getLanguageId() . '; Path=/; Max-Age=' . (60*60*24*30));
}
return $response;
}
Expand Down

0 comments on commit b00a866

Please sign in to comment.