当前位置:网站首页>Brief analysis of PHP session principle
Brief analysis of PHP session principle
2022-07-02 06:54:00 【Xu Jirong】
List of articles
Why session control is needed ?( answer :http Protocol is stateless )
The following text cannot be found , A long time ago, I copied a lot of mixed articles locally , Sorry for the original author
Everybody knows , The Internet application layer protocols we currently use are basically based on HTTP and HTTPS Of , Their ability is Stateless , Only responsible for requests and responses . We tell the server what we need , The server returns me the corresponding resources . If there is no additional treatment , The server doesn't know who you are , It's impossible to show you the content related to you according to who you are .
HTTP The initial stage of the agreement is for academic exchange , But now the Internet is more and more widely used , Forum 、 Shopping websites and so on need to record user status ,cookie、session、token emerge as the times require , Our article Combine only PHP speak session, Check the others by yourself
session working process
session working process It can be divided into the following steps :
The browser requests the website for the first time , Server generation Session ID.
Generative Session ID Save to the server storage .
Generative Session ID Back to the browser , adopt set-cookie.
Browser received Session ID, This will be brought with you the next time you send a request Session ID.
The server received a message from the browser Session ID, from Session User status store found in store , Session creation .
Subsequent requests will exchange this Session ID, Have a stateful session .
Draw a flow chart 
PHP Medium session
Let's see PHP How to create Session
<?php
// start-up session
session_start();
// Declare a admin The variable of , And assign a null value .
$_session["admin"] = null;
>
session_start()
start-up session, according to session ID open session file , If not, create a ID( This Session ID Is a unique string generated by a series of algorithms ) And corresponding session file .
session_start() The function must precede the tag
$_SESSION
Storage and retrieval session Variable
The destruction session
unset()
unset() Used to release the specified session Variable , Just clear the value , And variables still exist
session_destroy()
Cancellation session, This is closing session, And delete the corresponding session The file . Cut off the connection between the client and the server .
session_destroy() Will reset session, You will lose all the stored session data .
session Penetration test
commonly session The penetration test passes the following three aspects , I don't know if it's all , Isn't it , Brothers can correct and add
1.session Session fixation test
example : Grab the bag and check the login twice session Is it worth the same
2.session Logout test
example : Log in and get session value , After logging out , carry session Value to make a request to the server , See if you can perform login operations
3.session Timeout tests
example : Whether to log out if the page is not operated for a long time session
边栏推荐
- Thread hierarchy in CUDA
- selenium备忘录:selenium\webdriver\remote\remote_connection.py:374: ResourceWarning: unclosed<xxxx>解决办法
- Loops in tensorrt
- JS create a custom JSON array
- Uploading attachments using Win32 in Web Automation
- In depth study of JVM bottom layer (IV): class file structure
- 由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
- qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
- Sublime text configuring PHP compilation environment
- Atcoder beginer contest 253 F - operations on a matrix / / tree array
猜你喜欢

sqli-labs通关汇总-page4

Blog directory of zzq -- updated on 20210601

Warp shuffle in CUDA

UEditor .Net版本任意文件上传漏洞复现

Utilisation de la carte et de foreach dans JS

Huawei mindspire open source internship machine test questions

Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件

Linux MySQL 5.6.51 community generic installation tutorial

Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决

Explanation and application of annotation and reflection
随机推荐
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
js的防抖和节流
js删除字符串的最后一位
Apt command reports certificate error certificate verification failed: the certificate is not trusted
No process runs when querying GPU, but the video memory is occupied
Dynamic global memory allocation and operation in CUDA
Asynchronous data copy in CUDA
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
sprintf_ How to use s
Solution to the black screen of win computer screenshot
In depth study of JVM bottom layer (IV): class file structure
查询GPU时无进程运行,但是显存却被占用了
Log - 7 - record a major error in missing documents (A4 paper)
Atcoder beginer contest 253 F - operations on a matrix / / tree array
微信小程序基础
In depth study of JVM bottom layer (V): class loading mechanism
js把一个数组分割成每三个一组
Fe - wechat applet - Bluetooth ble development research and use
PHP Session原理简析
Linux MySQL 5.6.51 community generic installation tutorial