<<css mode="next" class="sidebar"></css>> (((
- '''<a href="/docs/fCookie">Class Documentation</a>''' - <a href="/api/fCookie">API Reference</a> - <a href="https://github.com/flourishlib/flourish-classes/blob/master/fCookie.php" target="_blank">Source Code</a>
<<toc></toc>> )))
The fCookie class helps to make PHP’s cookie API more consistent, while adding the ability to set default parameters and create httponly cookies in older versions of PHP 5.
The static method ::set() is a wrapper around the function `setcookie()`, with the addition of optional [#DefaultParameters] and backwards compatibility for creating httponly cookies in PHP 5.1 and earlier. In addition, the expires parameter has been extended to allow any valid `strtotime()` string or a timestamp. Below are some examples of using `set()`:
Please note that `set()` follows the same functionality as `setcookie()` when it comes to deleting cookies and storing boolean values. Any value that is set to a cookie that is equal to `FALSE` will cause the cookie to be deleted. This means storing boolean values in a cookie is not recommended since a `FALSE` value will cause the cookie to be erased - instead use `'0'` and `'1'`. Also, setting the expiration date to a time in the past will cause the cookie to be deleted.
The static method ::get() replaces direct access to the `$_COOKIE` superglobal and adds the ability to specify default values if no cookie is found:
`get()` will also remove any slashes added by the ini setting `magic_quotes_gpc` being enabled.
The fCookie class also allows defining default parameters to use for ::set(). Since most sites will often use the same `$path`, `$domain`, `$secure` and `$httponly` parameters for cookies, setting default eliminates unnecessary duplication throughout the code. If a parameter is passed as `NULL` to `set()` and a default is defined, the default will be used. Here are the methods to set default parameters:
|| Parameter || Method || || `$expires` || ::setDefaultExpires() || || `$path` || ::setDefaultPath() || || `$domain` || ::setDefaultDomain() || || `$secure` || ::setDefaultSecure() || || `$httponly` || ::setDefaultHTTPOnly() ||