donglu9134 2012-03-12 03:36
浏览 195
已采纳

多个站点范围的cookie / $ config ['cookie_domain']

Under the site-enabled www.test.com, I have multiple VirtualHost configurations. ServerName varies (eg. test1.com, test2.com, test3.com) but points only into one DocumentRoot.

I can detect which server name the user is currently in by using $_SERVER['SERVER_NAME']. However we have a particular page which requires pointing to a specific subdomain. Enabling site-wide cookies is definitely a go for this project.

My concern thus: Is there anyway to have multiple $config['cookie_domain'] in config.php? So I can have this matching idea:

$server_name = $_SERVER['SERVER_NAME'];

if($server_name == "test1.com")
    $config['cookie_domain'] = ".test1.com";
else if($server_name == "test2.com")
    $config['cookie_domain'] = ".test2.com";
... // so on

I even tried adding this into config.php but no luck.

  • 写回答

1条回答 默认 最新

  • drtj40036 2012-03-12 04:03
    关注

    Yes, what you're doing should work for each individual domain, but the nature of cookies is that they are inherently not cross-domain. You'll need some additional magic to make cookies (or session data) accessible across multiple top-level domains.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失