duanqiang2617 2016-12-06 09:11
浏览 7
已采纳

不需要的共享会话

I have 3 sites:

  • bbb.aaa.com
  • ccc.bbb.aaa.com
  • ddd.bbb.aaa.com

In this scenario, if the sites are on the same server, in IE (and only in IE) all the sites have the same php session id. This means that somehow the session is shared between them. I do not want this behavior, I'd like them to have separated sessions.

Can someone provide me any explanation for this and any advice for handling this?

(If I had domains without the aaa part, everything would work well.)

  • 写回答

1条回答 默认 最新

  • douyan1970 2016-12-06 09:31
    关注

    You can change the session name, from the default PHPSESSID to a custom name for each sites. You can do it with session_name:

    // change the session name for bbb.aaa.com
    session_name('PHPSESSID_bbb_aaa_com');
    

    It will be used that name to create a cookie name, unique for each domain.

    Then you can change the domain attribute of the cookie for each domain. You can do it by changing the session.cookie_domain on your php.ini file.

    ; instead of allows all the subdomain with ".aaa.com", specify them with:
    session.cookie_domain = bbb.aaa.com
    

    You can also do it at runtime with session_set_cookie_params.

    However, this isn't enough! If the session id is the same, even if you used different session names, the same data will be loaded, if the session informations are stored in a shared folder. To solve this problem, you can change the session.save_path configuration directive to an unique folder for each domain. You can do it at runtime with session_save_path:

    session_save_path('/path/to/sess_for_bbb_aaa_com');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败