Session technology
cookie
A technology that allows server-side scripts to store data in the browser,
Allows the server to send instructions to the browser to manage cookie data stored on the browser side
If the browser stores cookie data stored by a server, it will bring the cookie data when making requests
<code><span>//增、改</span><span>setcookie(key,val)</span>;
<span>//删</span><span>setcookie(key,<span>''</span>)</span>;
<span>//获取浏览器携带的cookie数据</span>
$_COOKIE<span>[key]</span></code>
Copy after login
Features:
-
Validity period:
The default is a temporary cookie, also called a session cookie. The session ends (the browser is closed ) to clear. The lifetime can be determined by setting the timestamp (from the first second in 1970), and the browser time uses Greenwich Mean Time (GMT) as the standard
<code><span>setcookie(key,val,<span>time()</span>+<span>60</span>)</span>;
<span>//代表保存1分钟,浏览器会检查是否失效</span><span>setcookie(key,val,<span>0</span>)</span>;
<span>//默认会话</span><span>setcookie(key,<span>''</span>,<span>time()</span>-<span>1</span>)</span>;
<span>//删除cookie</span><span>setcookie(key,val,PHP_INT_MAX)</span>;
<span>//逻辑上表示永久有效</span></code>
Copy after login
- Valid path:
Valid by default on the current path and its descendant paths. (The path is not the local disk path of the file where the code is located, but the path relationship of the url request)
Cookies with the same name under different paths can be stored in the browser at the same time. The browser will first search for valid cookies in the current directory, and then search upwards. All valid cookies will be carried to the server. When $_COOKIE is formed on the server side, a rewriting effect will occur. Whichever comes first is reserved,
You can set the fourth parameter of setcookie() to '/' to indicate that the site root directory is valid, that is, the entire site is valid. The effective path is determined by the browser. When setting the effective path, the server will inform the browser
<code> setcookie(<span>key</span>,val,<span>0</span>,<span>'/');</span></code>
Copy after login
- Valid domain:
The default cookie is only valid in the current domain
You can set the valid domain of the cookie to extend to all subdomains under a certain first-level domain name
<code> me.com <span>//一级域名</span>
lig.me.com <span>//二级域名</span>
bee.me.com <span>//二级域名</span>
setcookie(key,<span>val</span>,<span>0</span>,<span>''</span>,<span>'me.com'</span>);</code>
Copy after login
- Whether it is only secure transmission
By default, regardless of whether the browser sends http or https protocols, it will carry valid cookies to the server
You can set the sixth parameter to true to activate secure transmission only. At this time, if the browser sends a request using the http protocol, it will not send these cookies set to secure transmission only. Apache needs to load the openssl module to use the https protocol.
<code> setcookie(key,<span>val</span>,<span>0</span>,<span>''</span>,<span>''</span>,<span>true</span>);</code>
Copy after login
- HTTPonly
Scripts stored by the default browser can be called and processed by other scripts
By setting the 7th parameter, the cookie can only be used in http requests
<code> setcookie(key,<span>val</span>,<span>0</span>,<span>''</span>,<span>''</span>,<span>false</span>,<span>true</span>);</code>
Copy after login
').addClass('pre-numbering').hide();
$(this).addClass('has-numbering').parent().append($numbering);
for (i = 1; i ').text(i));
};
$numbering.fadeIn(1700);
});
});
The above is an introduction to cookies in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.