当前位置:网站首页>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";
边栏推荐
- ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
- 阿飞的期望
- How can technology managers quickly improve leadership?
- Microservices Seata distributed transactions
- Calibre LVL
- Chinese translation of Tagore's floating birds (1~10)
- App移动端测试【3】ADB命令
- The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
- TCP拥塞控制详解 | 3. 设计空间
- 切入点表达式
猜你喜欢

Microservice - Nacos registration center and configuration center

Create gradle project

How can technology managers quickly improve leadership?

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

记一次jar包冲突解决过程

Project -- high concurrency memory pool

TCP拥塞控制详解 | 3. 设计空间

Jmeter线程组功能介绍

Distributed task scheduling XXL job

Uploads labs range (with source code analysis) (under update)
随机推荐
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display
《天天数学》连载56:二月二十五日
Microservices Seata distributed transactions
Expression of request header in different countries and languages
CString getbuffer and releasebuffer instructions
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
Unity项目优化案例一
How can technology managers quickly improve leadership?
“用Android复刻Apple产品UI”(3)—优雅的数据统计图表
Intelij idea efficient skills (III)
Go语言自学系列 | golang switch语句
请求头不同国家和语言的表示
LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
Reflection on some things
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
Create gradle project
Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解