User Tools

Site Tools




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]]]] )


  • $Days Int (optional)
    Validity of the cookie in days.
  • $Hours Int (optional)
    Validity of the cookie in hours.
  • $Minutes Int (optional)
    Validity of the cookie in minutes
  • $Seconds Int (optional)
    Validity of the cookie in seconds


  • Int
    Calculated lifespan of the cookie in seconds


$Cookie = new CookieHandler("Testcookie");
   // 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
      // Every other exception is displayed on the screen
      echo "Error: " . $e->getMessage();
libraries/cookiehandler/cookiehandlerclass/setvalidity.txt · Last modified: 2022/12/13 19:54 by