当前位置:网站首页>Reasons and Countermeasures for ThinkPHP's session being unable to obtain session in different ways in the same controller
Reasons and Countermeasures for ThinkPHP's session being unable to obtain session in different ways in the same controller
2022-06-22 04:26:00 【An Yuwei】
1.( recommend ) Use TP5 Built in cache method
Can perfectly replace session, You can even set the time manually for each , Than session More convenient ,
( Used to tp5 Bring their own session Of course ,session Time is usually fixed , Very stiff to use ).
// Set the cache ( The period of validity 3600 second )
Cache::set('name',$value,3600);
// To get cached data, you can use :
Cache::get('name');As a reminder , If $value If it is an array, you have to json_encode() Encode it into a string and then
2.Redis Method ( This method is a little more cumbersome )
Follow the tutorial to configure on the server redis database
Use the method directly to the code :
// Deposit in redis
// Turn on redis Database services
$redis = new Redis();
// Connect ridis database
$redis->connect('127.0.0.1', 6379);
// In the data ( The period of validity 3600 second )
$redis->set($sessioncode,$value, 3600);
// Take out redis
// Turn on redis Database services
$redis = new Redis();
// Connect ridis database
$redis->connect('127.0.0.1', 6379);
// Take out the data
$data = $redis->get($session);Again , As a reminder , If $value If it is an array, you have to json_encode() Encode it into a string and then
3. Use memcache
边栏推荐
- [BP regression prediction] optimize BP regression prediction based on MATLAB GA (including comparison before optimization) [including Matlab source code 1901]
- Handling of noready fault in kubernetes cluster
- 图的DFS
- fc2新域名有什么价值?如何解析到网站?
- Specific concept of interceptor
- Large website technology architecture | application server security defense
- Ora-48132 ora-48170 appears in the alarm log
- Tencent side
- Redis和MySQL如何保持数据一致性?强一致性,弱一致性,最终一致性
- Spark - executor initialization &
猜你喜欢

CentOS uses composer install to report an error - phpunitphppunit 8

PCM data format

Digital economy Wang Ning teaches you how to correctly choose short-term investment

Fonctionnement de base du tableau de séquence

Online document collaboration: a necessary efficient artifact for office

Idea installation and use tutorial

Laravel implements soft deletion

拓扑排序

Huffman tree

Solutions pour l'écran bleu idea
随机推荐
Basic operation of sequence table
套用这套模板,玩转周报、月报、年报更省事
Idea installation and use tutorial
How does twitter decentralize? Look at these ten socialfi projects
Read stream special attention
IDEA蓝屏的解决方案
Daily question: the difference between ArrayList and LinkedList
Sequential implementation of queues
图的基本概念
物联网UWB技术方案,智能UWB精准定位,厘米级定位精度
Solutions pour l'écran bleu idea
Lua exports as an external link library and uses
[you don't understand the routing strategy? Try it!]
Redis和MySQL如何保持数据一致性?强一致性,弱一致性,最终一致性
Go learning notes
On the income of enterprise executives
ES无法工作,CircuitBreakingException
Some details
順序錶的基本操作
IDS interview questions collection data structure + penetration avalanche + persistence + memory elimination strategy + database double write + Sentinel