I would like to have my session work in my website when using www. AND when not using it. I\'ve read this thread: PHP cookie problem - www or without www
And this would
You can reflect php.ini
for this. Add this in php.ini so that your session cookie will be saved at the place to be accessible with or without www
session.cookie_domain = .example.com
You can also try an alternate to do this
ini_set("session.cookie_domain", ".example.com");
And you can get the host name using $_SERVER['HTTP_HOST']
variable.