PHPackages                             kalenjordan/jquery-cookie - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kalenjordan/jquery-cookie

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kalenjordan/jquery-cookie
=========================

The jquery-cookie library

0161JavaScript

Since Sep 30Pushed 12y ago1 watchersCompare

[ Source](https://github.com/kalenjordan/jquery-cookie)[ Packagist](https://packagist.org/packages/kalenjordan/jquery-cookie)[ RSS](/packages/kalenjordan-jquery-cookie/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

jquery.cookie [![Build Status](https://camo.githubusercontent.com/8ed31526a64fdb345c5c444a7b34e0dd35340e01763bc6c06b9d92b230ce6161/68747470733a2f2f7472617669732d63692e6f72672f636172686172746c2f6a71756572792d636f6f6b69652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/carhartl/jquery-cookie)
===============================================================================================================================================================================================================================================================================================================

[](#jquerycookie-)

A simple, lightweight jQuery plugin for reading, writing and deleting cookies.

Installation
------------

[](#installation)

Include script *after* the jQuery library (unless you are packaging scripts somehow else):

```

```

**Do not include the script directly from GitHub (...).** The file is being served as text/plain and as such being blocked in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN.

The plugin can also be loaded as AMD module.

Usage
-----

[](#usage)

Create session cookie:

```
$.cookie('the_cookie', 'the_value');

```

Create expiring cookie, 7 days from then:

```
$.cookie('the_cookie', 'the_value', { expires: 7 });

```

Create expiring cookie, valid across entire site:

```
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });

```

Read cookie:

```
$.cookie('the_cookie'); // => "the_value"
$.cookie('not_existing'); // => undefined

```

Read all available cookies:

```
$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }

```

Delete cookie:

```
// Returns true when cookie was found, false when no cookie was found...
$.removeCookie('the_cookie');

// Same path as when the cookie was written...
$.removeCookie('the_cookie', { path: '/' });

```

*Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.*

Configuration
-------------

[](#configuration)

### raw

[](#raw)

By default the cookie value is encoded/decoded when writing/reading, using `encodeURIComponent`/`decodeURIComponent`. Bypass this by setting raw to true:

```
$.cookie.raw = true;

```

### json

[](#json)

Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`:

```
$.cookie.json = true;

```

Cookie Options
--------------

[](#cookie-options)

Cookie attributes can be set globally by setting properties of the `$.cookie.defaults` object or individually for each call to `$.cookie()` by passing a plain object to the options argument. Per-call options override the default options.

### expires

[](#expires)

```
expires: 365

```

Define lifetime of the cookie. Value can be a `Number` which will be interpreted as days from time of creation or a `Date` object. If omitted, the cookie becomes a session cookie.

### path

[](#path)

```
path: '/'

```

Define the path where the cookie is valid. *By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior).* If you want to make it available for instance across the entire domain use `path: '/'`. Default: path of page where the cookie was created.

**Note regarding Internet Explorer:**

> Due to an obscure bug in the underlying WinINET InternetGetCookie implementation, IE’s document.cookie will not return a cookie if it was set with a path attribute containing a filename.

(From [Internet Explorer Cookie Internals (FAQ)](http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx))

This means one cannot set a path using `path: window.location.pathname` in case such pathname contains a filename like so: `/check.html` (or at least, such cookie cannot be read correctly).

### domain

[](#domain)

```
domain: 'example.com'

```

Define the domain where the cookie is valid. Default: domain of page where the cookie was created.

### secure

[](#secure)

```
secure: true

```

If true, the cookie transmission requires a secure protocol (https). Default: `false`.

Contributing
------------

[](#contributing)

Check out the [Contributing Guidelines](CONTRIBUTING.md)

Authors
-------

[](#authors)

[Klaus Hartl](https://github.com/carhartl)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1542197?v=4)[kalenjordan](/maintainers/kalenjordan)[@kalenjordan](https://github.com/kalenjordan)

---

Top Contributors

[![carhartl](https://avatars.githubusercontent.com/u/21918?v=4)](https://github.com/carhartl "carhartl (132 commits)")[![FagnerMartinsBrack](https://avatars.githubusercontent.com/u/835857?v=4)](https://github.com/FagnerMartinsBrack "FagnerMartinsBrack (21 commits)")[![kswedberg](https://avatars.githubusercontent.com/u/3485?v=4)](https://github.com/kswedberg "kswedberg (3 commits)")[![kalenjordan](https://avatars.githubusercontent.com/u/1542197?v=4)](https://github.com/kalenjordan "kalenjordan (1 commits)")[![tomkins](https://avatars.githubusercontent.com/u/177332?v=4)](https://github.com/tomkins "tomkins (1 commits)")[![bunnymatic](https://avatars.githubusercontent.com/u/427380?v=4)](https://github.com/bunnymatic "bunnymatic (1 commits)")[![vlakoff](https://avatars.githubusercontent.com/u/544424?v=4)](https://github.com/vlakoff "vlakoff (1 commits)")[![coryschires](https://avatars.githubusercontent.com/u/104563?v=4)](https://github.com/coryschires "coryschires (1 commits)")[![duncansmart](https://avatars.githubusercontent.com/u/576343?v=4)](https://github.com/duncansmart "duncansmart (1 commits)")

### Embed Badge

![Health badge](/badges/kalenjordan-jquery-cookie/health.svg)

```
[![Health](https://phpackages.com/badges/kalenjordan-jquery-cookie/health.svg)](https://phpackages.com/packages/kalenjordan-jquery-cookie)
```

###  Alternatives

[markbaker/phpgeodetic

Geodetic library

2013.0k](/packages/markbaker-phpgeodetic)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
