Contents
The server sets a cookie with the Set-Cookie response header, and from then on the browser sends it back in the Cookie header with every request to that domain. Without cookies, visitors would have to log in again on every page, because HTTP is stateless.
Example: what a cookie looks like
Set-Cookie: session_id=a8f3c2; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=86400
On following requests, the browser sends:
Cookie: session_id=a8f3c2
Cookie attributes
| Attribute | What it does |
|---|---|
Expires or Max-Age |
How long to keep it; without one it’s deleted when the browser closes (a session cookie) |
Domain and Path |
Which domain and path it’s sent to |
Secure |
Sent over HTTPS only |
HttpOnly |
Hidden from JavaScript, protecting it from theft via XSS |
SameSite |
Controls whether it’s sent with requests coming from other sites: Strict, Lax or None |
Types of cookies
- First-party cookies: set by the site you’re visiting; essential for logins, carts and language choice.
- Third-party cookies: set by other domains, such as ad networks, to track users across sites; browsers restrict them more and more.
Common problems
- WordPress login loop: the cookie isn’t saved because of a mismatch between
wwwand non-www, or between HTTP and HTTPS. See login loop. - Laravel 419 error: the session cookie or its CSRF token expired. See 419 page expired.
- The cache shows one user’s page to another: pages that depend on login or cart cookies must never be cached for everyone.
- Cookie consent: data-protection laws in many countries require visitors to agree to non-essential cookies, so check local regulations.
On ArabyHost
Cookies with the Secure flag need HTTPS, and on ArabyHost a free SSL certificate is issued for every site automatically. On WordPress and WooCommerce sites, the LiteSpeed Cache plugin is aware of login and cart cookies, so one user’s personal pages aren’t served to others from the public cache. If you run into session problems, the Araby AI assistant reads the error log and explains the cause.
FAQ
Are cookies a privacy risk?
Cookies are plain text and can't run programs. The privacy concern comes from third-party cookies that follow you across sites for advertising, and you can block those in your browser settings.
What happens if I clear my cookies?
You're logged out of sites, unsaved carts are emptied and site preferences reset to their defaults. Clearing cookies is a common fix for login problems and redirect loops.
What's the difference between cookies and localStorage?
Cookies are sent to the server automatically with every request and each one holds about 4 KB. localStorage stays in the browser, is never sent to the server and holds more, but JavaScript can always read it.