1. Go to this page and download the library: Download rafaeldms/cookie 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/ */
rafaeldms / cookie example snippets
use RafaelDms\Cookie\StaticCookie;
/**
* Create a new cookie using the static method
*/
StaticCookie::setCookie::set("test", "new_test", 10);
/**
* get value the static method
*/
echo StaticCookie::get("test");
echo "<br><br>";
/**
* Create value as array
*/
StaticCookie::set('user', ['name' => 'Rafael', 'role' => "Developer"], 10);
/**
* get value as array the static method
*/
echo StaticCookie::get('user')['role'];
echo "<br><br>";
/**
* remove the static class
*/
StaticCookie::destroy('test');
/**
* create if it doesn't exist the static method
*/
StaticCookie::setDoesntHave('testIfDoesntHave', true, 10000);
/**
* create if it doesn't exist the static method
*/
StaticCookie::setDoesntHave('testIfDoesntHave', 'ok', 12500, "/admin", true);
/**
* check if exists cookie the static class
*/
if (StaticCookie::has('testIfDoesntHave')) {
echo "Cookie testIfDoesntHave exist";
} else {
echo "Cookie testIfDoesntHave not exist";
}
echo "<br><br>";
/**
* check if exists by value
*/
if (StaticCookie::has("testIfDoesntHave", 1)) {
echo "the value is equal to ok";
} else {
echo "the vlaue is no equal to ok";
}
echo "<br><br>";
use RafaelDms\Cookie\Cookie;
/**
* Create a new cookie using construct method
*/
$cookie = new Cookie("testCookie");
/**
* set value a cookie using methot set
*/
$cookie->setValue("123456");
/**
* set expiryTime
*/
$cookie->setExpiryTime(24 * 60 * 60);
/**
* set path
*/
$cookie->setPath("/admin");
/**
* set domain
*/
$cookie->setDomain("https://www.cagep.com.br");
/**
* set httpOnly to false
*/
$cookie->setHttpOnly(false);
/**
* set secure only to true
*/
$cookie->setSecureOnly(true);
/**
* save a cookies
*/
$cookie->saveAndSet();
var_dump($cookie);
/**
* get value
*/
echo "Value: " . $cookie->getValue();
echo "<br><br>";
/**
* get expire time
*/
echo "Expire Time: " . $cookie->getExpiryTime();
echo "<br><br>";