当前位置:网站首页>PHP Session原理简析
PHP Session原理简析
2022-07-02 06:23:00 【徐记荣】
为什么需要会话控制?(答:http协议是无状态的)
以下文字找不到出处了,我是很久之前好多文章混杂的抄在本地,原文作者见谅
大家都知道,我们目前使用的互联网应用层协议基本上都是基于HTTP和HTTPS的,它们的本事是无状态的,只负责请求和响应。我们告诉服务器我们需要什么,服务器返回给我相应的资源。如果没有额外处理的话,服务器是不知道你是谁,更无法根据你是谁给你展现和你相关的内容了。
HTTP协议初期是为了学术交流,但如今互联网应用越来越广泛,论坛、购物网站等等都需要记录用户状态,cookie、session、token应运而生,我们这篇文章只结合PHP讲session,其他的你们自己查
session工作过程
session工作过程可以分为以下几个步骤:
浏览器第一次请求网站,服务端生成Session ID。
把生成的Session ID保存到服务端存储中。
把生成的Session ID返回给浏览器,通过set-cookie。
浏览器收到Session ID,在下一次发送请求时就会带上这个Session ID。
服务端收到浏览器发来的Session ID,从Session存储中找到用户状态存储,会话建立。
此后的请求都会交换这个Session ID,进行有状态的会话。
画了个流程图
PHP中的session
我们看一下PHP如何创建Session
<?php
// 启动session
session_start();
// 声明一个名为admin的变量,并赋空值。
$_session["admin"] = null;
>
session_start()
启动session,根据session ID打开session文件,如果没有就创建一个ID(这个Session ID是通过一系列算法生成的一个唯一字符串)和对应的session文件。
session_start()函数必须位于标签之前
$_SESSION
存储和取回session变量
销毁session
unset()
unset()用于释放指定的session变量,只是把值清空,而变量还是存在的
session_destroy()
注销session,这个就是关闭session,并删除掉相应的session文件了。切断了客户端和服务端的联系。
session_destroy() 将重置 session,您将失去所有已存储的 session 数据。
session渗透测试
一般session渗透测试通过以下三个方面,我不知道全不全,对不对,大哥们可以指正补充
1.session会话固定测
例:抓包看看两次登录session值是否一样
2.session注销测试
例:登录后获得session值,退出登录后,携带session值对服务器发起请求,看看能不能够做登录态的操作
3.session超时测试
例:页面长时间不操作是否注销session
边栏推荐
- js的防抖和节流
- CUDA user object
- 20201002 vs 2019 qt5.14 developed program packaging
- Shardingsphere JDBC
- pytest(3)parametrize参数化
- Huawei mindspire open source internship machine test questions
- sqli-labs通关汇总-page3
- Overload global and member new/delete
- Implement strstr() II
- unittest. Texttestrunner does not generate TXT test reports
猜你喜欢

Latex warning: citation "*****" on page y undefined on input line*

Uploading attachments using Win32 in Web Automation

AWD learning

In depth study of JVM bottom layer (V): class loading mechanism

Recursion (maze problem, Queen 8 problem)

由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决

Sentry construction and use

Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决

Explanation and application of annotation and reflection

js中map和forEach的用法
随机推荐
Usage of map and foreach in JS
Sentry construction and use
flex九宫格布局
[self cultivation of programmers] - Reflection on job hunting Part II
Log - 7 - record a major error in missing documents (A4 paper)
PIP install
微信小程序基础
DeprecationWarning: . ix is deprecated. Please use. loc for label based indexing or. iloc for positi
CTF web practice competition
Code execution sequence with and without resolve in promise
Asynchronous data copy in CUDA
There are multiple good constructors and room will problem
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)
Solution to the black screen of win computer screenshot
Pytest (2) mark function
Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
Win10: add or delete boot items, and add user-defined boot files to boot items
Linux MySQL 5.6.51 Community Generic 安装教程
浏览器滚动加载更多实现