php - session control, php session_PHP tutorial

WBOY
Release: 2016-07-12 08:58:31
Original
834 people have browsed it

php - session control, php session

1. What is session control

Allows the server to respond to successive requests made by the client.

2. Why do you need session control?

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.

3.The principle and function of cookies

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

4. How to use Cooike (General)

Create Cookie

<span>setCookie</span>("key","value",retainTime);<span>//</span><span>创建Cookie</span>
Copy after login

Call Cookie

<span>if</span> (<span>$_COOKIE</span>["key"] == "admin"<span>){ <span>//Cookie是php提供的超级数组
  </span></span><span>echo</span> "获取数据成功"<span>;       
}</span>
Copy after login

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>
Copy after login

Cookie supports turning into multi-dimensional array

<span>setCookie</span>("user[key]","values"); <span>//</span><span>相当于$_COOKIE["user"]["key"]</span>
Copy after login


Simple example: Cookie-based user login

5.The principle and function of Session

Store information on the server instead of on your personal PC.

6. How to use Session

(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>
Copy after login

Function: Preload the built-in environment variables related to Session into memory.

(3) Call

<span>$_SESSION</span>["key"] = "value";<span>//</span><span>$_SESSION也是超级数组,并以数组方式调用</span>
Copy after login

(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();
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1103618.htmlTechArticlephp - session control, php session 1. What is session control? Allow the server to make continuous requests based on the client . 2. Why do you need session control? Because when you open a website,...
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!