当前位置:网站首页>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";
边栏推荐
猜你喜欢

App移动端测试【4】apk的操纵

Nifi from introduction to practice (nanny level tutorial) - flow
![[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix](/img/d6/3c21c25f1c750f17aeb871124e80f4.png)
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix

Mongodb installation and basic operation

App移动端测试【5】文件的写入、读取

uploads-labs靶场(附源码分析)(更新中)

Low level version of drawing interface (explain each step in detail)

WinDbg analysis dump file

Record a jar package conflict resolution process

Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
随机推荐
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
App移动端测试【3】ADB命令
突破100万,剑指200万!
Is it safe to open an account with tongdaxin?
"Remake Apple product UI with Android" (2) -- silky Appstore card transition animation
How to use AAB to APK and APK to AAB of Google play apps on the shelves
0214-27100 a day with little fluctuation
Redis高可用与持久化
Redis installation under windows and Linux systems
Semi supervised learning
From the 18th line to the first line, the new story of the network security industry
Problems of CString in multithreading
Remote file contains actual operation
App mobile terminal test [3] ADB command
The wonderful use of do{}while()
How idea starts run dashboard
nifi从入门到实战(保姆级教程)——flow
“用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画
探索Cassandra的去中心化分布式架构