CookieHandler::SetValidity()


Definition

Uses the existing parameters to set the validity/lifespan in seconds, which is used to calculate the expiry Unix timestamp when the cookie is set.
The parameters can be combined in any way and describe the lifespan of the cookie (e.g. “Valid for 3 days, 12 hours and 30 minutes”).
If no parameter is given or every one is 0, the cookie is valid till the end of the current browser session.

Int SetValidity ( [$Days = 0, [$Hours = 0, [$Minutes = 0, [$Seconds = 0]]]] )

Parameters

Returns

Example

$Cookie = new CookieHandler("Testcookie");
 
try 
{
   // Cookie should expire in 1 day and 12 hours
   $Cookie->SetValidity(1, 12);
}
catch (CookieHandlerException $e)
{
   if ($e->getCode() == CookieHandlerException::$EC_INVALIDNUMBER)
   {
      // If there was a parameter error, the cookie is only valid for this browser session
      $Cookie->SetValidity();
   }
   else
   {
      // Every other exception is displayed on the screen
      echo "Error: " . $e->getMessage();
   }
}