当前位置:网站首页>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
边栏推荐
- selenium+msedgedriver+edge浏览器安装驱动的坑
- 如何调试微信内置浏览器应用(企业号、公众号、订阅号)
- js中对于返回Promise对象的语句如何try catch
- Latex error: the font size command \normalsize is not defined problem solved
- Log - 7 - record a major error in missing documents (A4 paper)
- In depth study of JVM bottom layer (II): hotspot virtual machine object
- PgSQL learning notes
- Uniapp introduces local fonts
- There are multiple good constructors and room will problem
- Implement strstr() II
猜你喜欢
Sublime text configuring PHP compilation environment
There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)
UEditor .Net版本任意文件上传漏洞复现
js中对于返回Promise对象的语句如何try catch
Latex error: the font size command \normalsize is not defined problem solved
Sqli - Labs Clearance (less6 - less14)
Apt command reports certificate error certificate verification failed: the certificate is not trusted
Latex compiles Chinese in vscode and solves the problem of using Chinese path
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
unittest. Texttestrunner does not generate TXT test reports
随机推荐
部署api_automation_test过程中遇到的问题
CVE-2015-1635(MS15-034 )远程代码执行漏洞复现
Self cultivation of programmers - Reflection on job hunting
Common prototype methods of JS array
CVE-2015-1635(MS15-034 )遠程代碼執行漏洞複現
Anti shake and throttling of JS
默认google浏览器打不开链接(点击超链接没有反应)
sprintf_ How to use s
Latex error: the font size command \normalsize is not defined problem solved
Sublime text configuring PHP compilation environment
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
Usage of map and foreach in JS
js中map和forEach的用法
查询GPU时无进程运行,但是显存却被占用了
Linux MySQL 5.6.51 community generic installation tutorial
selenium的web自动化中常用的js-修改元素属性翻页
How to try catch statements that return promise objects in JS
JS modification element attribute flipping commonly used in selenium's Web Automation
Cve - 2015 - 1635 (ms15 - 034) réplication de la vulnérabilité d'exécution de code à distance
SQLI-LABS通关(less18-less20)