php Sessions not work well without www

前端 未结 3 1737
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 09:14

my sessions only work with a sub-domain, e.g. www. ,and do not work without that sub-domain.

For example, when a user is logged in.

If the address is n

相关标签:
3条回答
  • 2021-01-24 09:22

    If you want the php session to work all your subdomains, you must change cookie_domain option. Type this to top of your script:

    ini_set('session.cookie_domain', '.example.com' );
    
    0 讨论(0)
  • 2021-01-24 09:36

    i solved this probem use this code

    session_name("name");
    ini_set ("session.cookie_domain", '.domain.com') ;
    session_set_cookie_params(0, '/', '.domain.com');
    session_start();
    
    0 讨论(0)
  • 2021-01-24 09:41

    www.domain.com and domain.com are NOT the same website. They are the mirror copy of each other

    For this reason, cookies set on domain.com will NOT be used on www.domain.com and vice-verse, because it would be unsafe to assume they are the same thing.

    You can override this behavior to some extent by allowing the session cookie to work on all subdomains as well as the main domain by setting the php.ini setting session.cookie_domain to .domain.com

    0 讨论(0)
提交回复
热议问题