PHP code example of siteparts / http-message-cookies
1. Go to this page and download the library: Download siteparts/http-message-cookies library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
siteparts / http-message-cookies example snippets
use DateTime;
use SiteParts\Cookies\HttpMessage\ResponseCookieTemplate;
$cookieTemplate = new ResponseCookieTemplate([
'domain' => 'example.org',
'path' => '/foo',
'expires' => new DateTime("+14 days"),
]);
// $response is instance of Psr\Http\Message\ResponseInterface
$response = $cookieTemplate
->create("lang", "en")
->addTo($response);
$response = $cookieTemplate
->create("color", "blue")
->withSecure(true)
->addTo($response);
use DateTime;
use SiteParts\Cookies\HttpMessage\ResponseCookie;
// $response is instance of Psr\Http\Message\ResponseInterface
$response = new ResponseCookie("lang", "en")
->withDomain("example.org")
->withPath("/foo")
->withExpires(new DateTime("+14 days"))
->addTo($response);
$response = new ResponseCookie("color", "blue")
->withDomain("example.org")
->withPath("/foo")
->withExpires(new DateTime("+14 days"))
->withSecure(true)
->addTo($response);