惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

博客园 - 懒牛拉车

xxx tmp Thinkphp 3.2 Cookie丢失导致中英文混排 第一个python自动化实例 Nginx配置文件下载 每次用npm都很烦人 js 判断mac地址是否为组播地址 项目在本地时,css/js文件在浏览器刷新时,从(memory cache)读取,放服务器上就不会 模拟json_decode解析非法utf-8编码字符串 php socket 循环ping ip,显示能ping通的IP地址 Thikphp 3.2 session页面传递失败问题 火狐autocomplete="off"无效 testlink windows 安装笔记 宝塔面板部署thinkcmf问题 coreseek 測試用例 coreseek 基与Sphinx 的全文索引 centos6 nginx 配置本地https访问 centos6 nginx安装好以后,添加拓展ssl centos6 php7 安装 memcache 和 memcached - 懒牛拉车 centos7 搭建 php7 + nginx (2) - 懒牛拉车 centos7 搭建 php7 + nginx (1)
thinkphp3.2.2 CheckLangBehavior.class中,使用session无效原因分析
懒牛拉车 · 2021-04-27 · via 博客园 - 懒牛拉车

问题场景:
网站使用“中文版”,“英文版”切换,也就是双语版网站。官网的多语言是指根据客户浏览器版本自动切换中英文(不满足手动切换语言版本要求)。
手动切换语言版本的时候,我们会将网站语言版本存入session中,以供页面使用。但此时 L 函数还是会返回中文

主要原因:
在CheckLangBehavior.class这个类中,使用session的时候,session_start()还没有执行,所以无法读取;

过程分析:
关于语言加载,程序执行过程大概是这样
index.php -> 加载多语言文件(加载实际是中文) -> session启动 -> 控制器通过L函数读取翻译
而我们理想的过程是这样
index.php -> session启动 ->加载多语言文件(加载英文) -> 控制器通过L函数读取翻译

快速解决办法:

  1. 修改tags.php文件

'app_begin' => array('Behavior\CheckLangBehavior'),
修改为
'action_begin' => array('Behavior\CheckLangBehavior'),
```
2. 所有url中都加上语言参数;

偏方:在index.php就启用session_start();但是这样有一个问题,就是配置文件里面的那些改变session配置的参数可能及不起作用了(例如session前缀 SESSION_PREFIX)

提示:session函数位置
ThinkPHP\Common\functions.php