跳到主要內容

使用jQuery的Plugin管理cookie

為了能在javascript上管理cookie,因此採用了jQuery的Plugin:jQuery.Cookie

如何使用呢?

上面的連結是連到github,可以看到有個README.md檔案,裡面有說明如何使用。
以下是範例內容
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
//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'); // => null

//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: '/' });

這時候就可用PHP印出cookie,確認是否有成功。
1
2
3
<?php
var_dump($_COOKIE);
?>

(其實這篇文章主要是記錄jQuery.Cookie的連結XD)

留言

這個網誌中的熱門文章

What is phpize

What is phpize According to the PHP official document : The phpize command is used to prepare the build environment for a PHP extension. If you need to build such an extension that from github or another code repositories, you can use  build tools to perform the build manually.