php之session熟悉了解
概念了解:
session在web主要指用户在浏览某个网站,从进入该网站到关闭这个网站经过的这段时间。
工作原理:
1.启动seesion,服务端会传给浏览器一个键值为PHPSESSID的唯一标识存储在本地的cookie中,同时会在服务器相应目录下根据键值生成一个对应的session文件
设置session值后,值就存在该session文件中
2.服务器php脚本读取session值的话,浏览器传回键值的唯一标识,通过启动session,然后根据键值可以从session仓库中加载已经存储的变量
3.当php脚本执行结束时,未被销毁的session变量会被自动保存在本地一定路径下唯一标识的session文件中,路径可以通过php.ini中的session.save_path设定
1.设置session值,得先启动session,后设置
session_start();$_SESSION['name'] = 'wyz';
2.读取session值
session_start();echo $_SESSION['name'];
a.针对单个
unset($_SESSION['name']);
b.针对所有
session_destroy();
4.设置session的唯一标识值cookie在浏览器上的保留时间,也可以说设置存放session值的时间
session_start(); $_SESSION['name'] = 'wyzss';$lifeTime = 24 * 3600;setcookie(session_name(), session_id(), time() + $lifeTime, "/");

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
