注意:这是一个高级教程。它要求您熟练掌握HTML,CSS,WordPress站点和PHP。
在内容设置下,您需要单击“Cookies”以打开cookie设置页面。
接下来,您需要单击“所有cookie和站点数据”选项。
在下一页上,您将看到您访问过的所有网站存储在浏览器中的所有Cookie和网站数据的列表。
您可以在搜索框中键入网站地址,它将显示该网站存储的数据。
单击单个项目将显示有关各个cookie及其内容的更多详细信息。
setcookie()在PHP中使用该函数。此函数接受以下参数。
|
1
2
3
4
5
6
7
8
9
10
11
12 |
function wpb_cookies_tutorial1() { $visit_time = date('F j, Y g:i a');if(!isset($_COOKIE[$wpb_visit_time])) {// set a cookie for 1 yearsetcookie('wpb_visit_time', $current_time, time()+31556926);}} |
wpb_visit_time。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 |
function wpb_cookies_tutorial2() { // Time of user's visit$visit_time = date('F j, Y g:i a');// Check if cookie is already setif(isset($_COOKIE['wpb_visit_time'])) {// Do this if cookie is set function visitor_greeting() {// Use information stored in the cookie $lastvisit = $_COOKIE['wpb_visit_time'];$string .= 'You last visited our website '. $lastvisit .'. Check out whats new'; return $string;} } else { // Do this if the cookie doesn't existfunction visitor_greeting() { $string .= 'New here? Check out these resources...' ;return $string;} // Set the cookiesetcookie('wpb_visit_time', $visit_time, time()+31556926);}// Add a shortcode add_shortcode('greet_me', 'visitor_greeting');} add_action('init', 'wpb_cookies_tutorial2'); |
|
1 |
unset($_COOKIE['wpb_visit_time']); |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 |
function wpb_cookies_tutorial2() { // Time of user's visit$visit_time = date('F j, Y g:i a');// Check if cookie is already setif(isset($_COOKIE['wpb_visit_time'])) {// Do this if cookie is set function visitor_greeting() {// Use information stored in the cookie $lastvisit = $_COOKIE['wpb_visit_time'];$string .= 'You last visited our website '. $lastvisit .'. Check out whats new'; // Delete the old cookie so that we can set it again with updated timeunset($_COOKIE['wpb_visit_time']); return $string;} } else { // Do this if the cookie doesn't existfunction visitor_greeting() { $string .= 'New here? Check out these resources...' ;return $string;} }add_shortcode('greet_me', 'visitor_greeting');// Set or Reset the cookiesetcookie('wpb_visit_time', $visit_time, time()+31556926);} add_action('init', 'wpb_cookies_tutorial2'); |