different session with url's with-www and without-www

后端 未结 5 660
猫巷女王i
猫巷女王i 2020-12-08 23:41

I have a interactive web site that has authors. When an author enters the site on www.mysite.com and logs in, the session varible becomes

$_SESSION[loggedid]         


        
相关标签:
5条回答
  • 2020-12-08 23:51

    Set your session.cookie_path to the domain .yourdomainname.tld, note the starting dot (.).

    0 讨论(0)
  • 2020-12-09 00:04

    It's RewriteRule

    ^(.*)$ http://www.mysite.com/$1 [R=permanent,L]

    and not

    $1 [R=permanent,L].

    If you add .com$1 [R=permanent,L] in php.ini and you try mysite.com/index.php?id=934 it redirects you to mysite.comindex.php/?id934

    0 讨论(0)
  • 2020-12-09 00:06

    Use this: http://ca3.php.net/session_set_cookie_params To set the domain to match all subdomains do this:

    session_set_cookie_params($lifetime, '/', '.domain.com');
    

    You need to use that before a calling session_start().

    You could use this code example taken straight from the link above, which let's you keep all the current settings except the domain:

    $currentCookieParams = session_get_cookie_params(); 
    
    $rootDomain = '.example.com'; 
    
    session_set_cookie_params( 
        $currentCookieParams["lifetime"], 
        $currentCookieParams["path"], 
        $rootDomain, 
        $currentCookieParams["secure"], 
        $currentCookieParams["httponly"] 
    ); 
    
    session_name('mysessionname'); 
    session_start(); 
    
    0 讨论(0)
  • 2020-12-09 00:14
    session.cookie_domain =
    

    php.ini directive

    try using

    session_set_cookie_params(0, '/', '.yourdomain.com');
    

    that leading dot means session will affect every domain. Be aware of SUHOSHIN! Sometimes it restricts this function!

    0 讨论(0)
  • 2020-12-09 00:15

    Add this to your .htaccess file:

    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^mysite\.com
    RewriteRule ^(.*)$ http://www.mysite.com$1 [R=permanent,L]
    
    0 讨论(0)
提交回复
热议问题