Simple application of cookies in php (recording login status)

WBOY
Release: 2016-07-25 08:59:13
Original
1103 people have browsed it
  1. setCookie('v1[name]','hey');
  2. setCookie('v2[age]','24');
  3. unserialize(($_COOKIE["name"])); // In fact, two cookie variables are set.
Copy code

2. The validity time of the cookie, which can be used to record the login status.

  1. if(isset($_POST['remember'])) {
  2. //Get the user ID and password from the database and set them in the cookie.
  3. setcookie('admin_id', $admin_user['admin_id'], time()+3600);
  4. setcookie('admin_pass', $admin_user['admin_pass'], time()+3600);
  5. }
Copy The code

first verifies the session. If there is no session, then verifies the above admin_id and admin_pass in the cookie. //There cannot be an output statement before jumping to the frameset, so delete the statement in time after debugging it in the code.

3. Valid path of cookie. The default is the root directory.

4. Cookie sharing The fifth parameter ‘jbxue.com’ means that the information in the cookie can be accessed at he.jbxue.com yong.jbxue.com jia.jbxue.com.

Notes: setCookie() only sets cookie information after a request. There cannot be any output before setCookie. Same as header. Response headers must be sent before the response body. Remember: there can be no output before the cookie.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template