CodeIgniter Forums
session data depending on 'www.' in URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: session data depending on 'www.' in URL (/showthread.php?tid=62553)



session data depending on 'www.' in URL - Ornis - 07-28-2015

Hi


Retrieving session data doesn't work properly anymore with me since Firefox, Vs. 39.0 (not in Chrome or Safari). The problem: I set session data over the URL 'www.mydomain.ch/login'. If I want to retrieve those session data over the address 'mydomain.ch/mycontroller' (without www.) I got redirected to the login page (meaning: no session data found).

This is annoying since some people use the website with 'www.' others without.

By the way: I have rewriting url already established in .htaccess (however without effect)

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Had anyone similar problems? How can I get around this? Should I make a sort of front-controller that redirects all 'domain.ch/controller' to 'www.domain.ch/controller'?

Thanks Martin


RE: session data depending on 'www.' in URL - Diederik - 07-28-2015

The problem isn't with sessions but with cookies. The session id is stored inside a cookie. Cookie are by default linked to a single domain so they dont share data between domain.com and www.domain.com

Inside config.php you should set it like so (notice the dot before the domainname)
'cookie_domain' = Set to .your-domain.com for site-wide cookies


RE: session data depending on 'www.' in URL - Ornis - 07-29-2015

(07-28-2015, 02:56 PM)Diederik Wrote: The problem isn't with sessions but with cookies. The session id is stored inside a cookie. Cookie are by default linked to a single domain so they dont share data between domain.com and www.domain.com

Inside config.php you should set it like so (notice the dot before the domainname)
'cookie_domain'   = Set to .your-domain.com for site-wide cookies


This solved the problem. Great. Thank you.