Home  >  Article  >  Backend Development  >  php cookie&session notes

php cookie&session notes

WBOY
WBOYOriginal
2016-07-25 08:46:22729browse

php cookie&session notes, friends in need can refer to it.


**

COOKIE

**
1. Create cookies
setcookie(name,value,expire,path,domain); The setcookie function must be in front of the label;
eg: setcookie(user,"zhuyumin",time()+3600);
Meaning: Create a user cookie, assign the value to zhuyumin, and this cookie will expire in one hour.
2. Get the cookie value
COOKIEeg:_COOKIE["user"]; //Get the value of cookie user;
COOKIE;//Get the values ​​of all cookies. 3. Determine whether cookieisset has been set (_COOKIE["user"]));
4. Delete cookies
Set the cookie's expire to the value of the past time.
eg:setcookie(“user”, “”, time()-3600);

**

SESSION

*


php session variable is used to store information about the user session, or to change the settings of the user session. The information held by the Session variable is single-user and available to all pages in the application.
The working mechanism of Session is to create a unique ID (UID) for each visitor and store variables based on this UID. The UID is stored in a cookie or via the URL.
guide.
Start session: session_start(); used in front of label;
Save session:$_SESSION("");
Terminate session
unset() ;
session_destroy() function deletes all saved session data.

cookie, php, session


Statement:
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