PHP code example of phpatom / cookies

1. Go to this page and download the library: Download phpatom/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/ */

    

phpatom / cookies example snippets



# create a new router

use Atom\Cookies\Cookie;
use Atom\Cookies\CookieConfig;

$myCookie = Cookie::create("foo","bar")
            ->withDomain("mydomain.com")
            ->withPath("/")
            ->thatExpiresOn("2 days");

$myCookie->applyTo($response); // ResponseInterface

// Cookie default config
CookieConfig::configure()
            ->withDomain("foo.com")
            ->withHttpOnly(true);

//will use default config
$myCookie = new Cookie("foo","bar");
echo $myCookie->getDomain(); // foo.com
echo $myCookie->isHttpOnly(); // true


 $cookies = Cookies::of($request);
 echo $cookies->get("key"); //value 
 echo $cookies->get("badkey",'defaultValue'); // defaultValue
 var_dump($cookies->getCookies("badkey")); // RequestCookie;
 echo $cookies->has("key"); //value boolean

 //also works with responses
 $cookies = Cookies::of($response);
 var_dump($cookies->getCookie("badkey")); // RequestCookie;Cookie