Whenever I switch from http://mysite.com to http://www.mysite.com or vice versa, the php session variables are lost. I know I can use the session id variable to tell php which session to use, but I would have to always put that in the url or set a cookie. Both do not sound like good options. Is there a way to make the php sessions stay from http:// to http://www? Or could I just redirect the site so whenever it is http://www. it becomes http:// ? Which one would work better?
set the configuration setting session.cookie_domain = .mysite.com
Notice the leading dot.
Set this in php.ini, .htaccess, or in the scripts via ini_set(). If you do it in the script, you need to do it before starting a session, and you need to do it in any and all files that call session_start()
You should use one or the other, you can do this in htaccess
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
I tried .htaccess but I ended up messing up my site. I just added it into the php.ini file, and everything is good now. Thanks for the help!