To set a cookie in PHP, you can use the setcookie()
function, which takes at least two parameters: the name of the cookie and its value.
main.php82 chars3 lines
By default, a cookie set with setcookie()
will expire when the user's browser is closed. However, you can set an expiration date using a third parameter, which takes a Unix timestamp or a string in the format YYYY-MM-DD HH:MM:SS
.
main.php163 chars4 lines
You can also set additional parameters such as the cookie's path, domain, and whether it should only be sent over HTTPS. For example, to make the cookie secure, you can pass true
as the fourth parameter.
main.php178 chars4 lines
Note that setcookie()
must be called before any output is sent to the browser, including whitespace.
gistlibby LogSnag