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

推荐订阅源

Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
罗磊的独立博客
宝玉的分享
宝玉的分享
Vercel News
Vercel News
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
T
Threatpost
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
I
Intezer
P
Privacy International News Feed
D
Docker
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
M
MIT News - Artificial intelligence
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
Lohrmann on Cybersecurity
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
A
Arctic Wolf
IT之家
IT之家
S
SegmentFault 最新的问题
S
Securelist
博客园 - 叶小钗
N
News and Events Feed by Topic
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - Franky
GbyAI
GbyAI
AI
AI
Y
Y Combinator Blog
WordPress大学
WordPress大学
Latest news
Latest news
Microsoft Security Blog
Microsoft Security Blog
人人都是产品经理
人人都是产品经理
N
News | PayPal Newsroom
The Cloudflare Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
I
InfoQ

博客园 - 懒牛拉车

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