Allows the server to respond to successive requests made by the client.
Because when you open a website and want to access other pages of the website, if there is no session control, you will need to enter your account and password again when jumping to other pages.
Save the client's simple information in the personal PC, and other programs obtain the PC's cookies to obtain the user's information. This eliminates the need for users to enter their account and password
Note: setCookie() must be used before php outputs the first sentence, otherwise it will be invalid
Create Cookie
<span>setCookie</span>("key","value",retainTime);<span>//</span><span>创建Cookie</span>
Call Cookie
<span>if</span> (<span>$_COOKIE</span>["key"] == "admin"<span>){ <span>//Cookie是php提供的超级数组 </span></span><span>echo</span> "获取数据成功"<span>; }</span>
Delete Cookies
<span>//</span><span>第一种方法</span> <span>setCookie</span>("key");<span>//</span><span>只需要输入键名即可 //第二种方法</span> <span>setCookie</span>("key","",<span>time</span>()-1000);<span>//</span><span>让保留的时间小于当前时间</span>
Cookie supports turning into multi-dimensional array
<span>setCookie</span>("user[key]","values"); <span>//</span><span>相当于$_COOKIE["user"]["key"]</span>
Simple example: Cookie-based user login
Store information on the server instead of on your personal PC.
(1). Configure php.ini options (don’t expand, check the relevant documents yourself)
(2).Start session
<span>session_start</span>();<span>//</span><span>在使用session之前都必须先调用该方法</span>
Function: Preload the built-in environment variables related to Session into memory.
(3) Call
<span>$_SESSION</span>["key"] = "value";<span>//</span><span>$_SESSION也是超级数组,并以数组方式调用</span>
(4)Delete
<span>//</span><span>单个删除</span> <span>unset</span>(<span>$_SESSION</span>["key"<span>]); </span><span>//</span><span>全部删除</span> <span>$_SESSION</span> = <span>array</span>(); <span>//</span><span>设置成空数组 //将这个用户在服务器端对应的Session文件删除</span> session_destory();