phpgt / cookie Goto Github PK
View Code? Open in Web Editor NEWObject oriented cookie handler.
Home Page: https://www.php.gt/cookie
License: MIT License
Object oriented cookie handler.
Home Page: https://www.php.gt/cookie
License: MIT License
With some random datasets this test fails. Run it a hundred times and see what happens...
Dependabot needs to be tamed, as per PhpGt/WebEngine#568
It's useful to encapsulate hierarchies of data.
The delete method uses setcookie
to set an empty cookie with negative expiry - the standard method for deleting a cookie - but what happens if the cookie was originally set on a path / domain?
When setting a cookie with the set
function and nothing else, Firefox emits this warning:
Cookie “cookie-name” will be soon rejected because it has the “sameSite” attribute set to “none” or an invalid value, without the “secure” attribute. To learn more about the “sameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite
Cookie
represents a single cookie header with name, value and optional other fields that setcookie()
takes. __toString
outputs the cookie header line.
Optional fields set in PSR style withX, withoutX:
Very useful for logging out.
$cookie->clear()
kills everything
$cookie->clear("user", "tracking");
kills only the two specified cookies, leaving others set.
CookieList
constructed with multiple Cookie
objects.
With the basics taken care of in Cookie and CookieList, use static classes for reading/writing cookies to/from PSR-7 Request/Response objects.
With/without style methods.
All other PHP.Gt repositories use contains
as well as native DOMDocument APIs.
There is no toString implementation, because the cookie model does not match the other objects of PHP.Gt - for example, I think the CookieStore idea in #39 will fix this.
Values of get
methods are set to return string
s. That's absolutely expected.
However, PHP implements the ability to store arrays as cookies like this:
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");
// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $value) {
$name = htmlspecialchars($name);
$value = htmlspecialchars($value);
echo "$name : $value <br />\n";
}
}
This isn't currently possible using this library, but it should be compatible, possibly utilising a getArray
method.
I personally don't like the idea of cookies being set using the array syntax because it means that browsers will send each element of the array as a separate cookie which just seems like a massive waste and massive hack.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.