当前位置:网站首页>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";
边栏推荐
- 大csv拆分和合并
- [combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
- Reflection on some things
- Three dimensional reconstruction of deep learning
- Intelij idea efficient skills (III)
- Microservices - load balancing ribbon
- Semi supervised learning
- First!! Is lancet hungry? Official documents
- Microservice - fuse hystrix
- 突破100万,剑指200万!
猜你喜欢

2022年Q2加密市场投融资报告:GameFi成为投资关键词

ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)

Mb10m-asemi rectifier bridge mb10m

请做好3年内随时失业的准备?

Principles of several common IO models

Project -- high concurrency memory pool

Vs2017 is driven by IP debugging (dual machine debugging)

Intelij idea efficient skills (III)
![App mobile terminal test [5] file writing and reading](/img/f1/4bff6e66b77d0f867bf7237019e982.png)
App mobile terminal test [5] file writing and reading
随机推荐
近视:摘镜or配镜?这些问题必须先了解清楚
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
Get the executable path through the process PID (queryfullprocessimagename)
App mobile terminal test [4] APK operation
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
疫情常态化大背景下,关于远程办公的思考|社区征文
Uploads labs range (with source code analysis) (under update)
App mobile terminal test [5] file writing and reading
CString getbuffer and releasebuffer instructions
【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)
pycharm错Error updating package list: connect timed out
Page dynamics [2]keyframes
Go language self-study series | if else if statement in golang
Automatic generation of client code from flask server code -- Introduction to flask native stubs Library
Microservice API gateway
0214-27100 a day with little fluctuation
深度学习之三维重建
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display
Create gradle project