当前位置:网站首页>PHP二级域名session共享方案
PHP二级域名session共享方案
2022-07-03 16:08:00 【星哥玩云】
一般来讲网站都会有主站和子站,比如域名是linuxidc.com,那么一般来讲linuxidc.com和www.linuxidc.com就会是主站,而像bbs.linuxidc.com就会作为论坛而存在的子站。
而且要注意的是,虽然一般设置域名dns解析的时候,都会将linuxidc.com和www.linuxidc.com都设置好指向主页虽然看起来效果是一样的。但是这两个确是不同的域名,也就是如果是默认的情况下的话,这两个域名的cookie的domain是认为不同的。
而一般,如果网站是有用户登录功能的,我们一般都希望不管是在什么样的二级域名中,都是保持这种登录状态的。
所以,为了解决这种二级域名session共享问题,推荐使用如下方案:
<?phpini_set("session.cookie_domain",'linuxidc.com');//注:此句必须放在session_start()之前session_start();
需要注意的是:
1、ini_set("session.cookie_domain",'linuxidc.com');必须放在session_start();之前。
2、域名linuxidc.com必须跟浏览器实际访问的域名是相匹配的。
其实道理很简单,就是将主域名和二级域名的domain都设置为主域名,这样就可以实现session在不同的二级域名之间共享访问了。
Ps.在PHP的CI框架中,如果想实现其自带的Session类可以在不同的二级域名中共享,则在/application/config/config.php文件中,做如下设置:
$config['cookie_domain'] = "linuxidc.com";
边栏推荐
- Brush questions -- sword finger offer
- 用通达信炒股开户安全吗?
- Break through 1million, sword finger 2million!
- Remote file contains actual operation
- The mixlab editing team is recruiting teammates~~
- Go language self-study series | if else if statement in golang
- Low level version of drawing interface (explain each step in detail)
- The difference between mutually exclusive objects and critical areas
- Page dynamics [2]keyframes
- [redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
猜你喜欢
突破100万,剑指200万!
First knowledge of database
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
Please be prepared to lose your job at any time within 3 years?
Mongodb installation and basic operation
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
Microservices Seata distributed transactions
Mb10m-asemi rectifier bridge mb10m
Colab works with Google cloud disk
随机推荐
2022年Q2加密市场投融资报告:GameFi成为投资关键词
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
六月 致 -.-- -..- -
Vs2017 is driven by IP debugging (dual machine debugging)
关于网页中的文本选择以及统计选中文本长度
Intelij idea efficient skills (III)
The wonderful use of do{}while()
Calibre LVL
Go语言自学系列 | golang中的if else语句
Shell script import and export data
大csv拆分和合并
Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
Multithread 02 thread join
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
Principles of several common IO models
Redis高可用与持久化
Microservice - declarative interface call openfeign
Project -- high concurrency memory pool
Record a jar package conflict resolution process