#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0

    Logged in at mysite.com but not www.mysite.com


    Hi

    Sorry if this is in the wrong place...

    I'm using sessions to manage logged in users on my site.

    If I log in at http://mysite.com everything works as normal, but when I go to http://www.mysite.com I'm treated as if I'm logged out and visa versa.

    Can someone explain why this is happening and how to fix it?

    Cheers
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,136
    Rep Power
    1990
    It's pretty easy really. The URL's 'mysite.com' and 'www.mysite.com' are not the same domain. They can be thanks to the way that most modern web servers are set up and most people think that they are interchangable, but they are not. As a normal thing, anything that's 'www.' is a sub-domain of 'mydomain.com'.

    What this means is that they are considered to be separate. Your web server looks at sessions for the single domain, and won't "transfer" these settings to the other domain, because in reality they are not the same.
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    If you set the domain on your application's login cookie to ".mydomain.com" it will be sent to both domains.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0
    Cheers, I'm not using cookies so can't use your solution E-Oreo.
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    If you weren't using cookies you wouldn't be having this problem. Session IDs are normally tracked using cookies.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    12
    Rep Power
    0
    Found this which sorts my problem - .htaccess rewrite rules

    Code:
    Options +FollowSymLinks
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L
    All explained at http://kb.mediatemple.net/questions/...+rewrite+rules
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Thanks Stevo.

    I had the same problem and now it fixed

IMN logo majestic logo threadwatch logo seochat tools logo