Salah Ud Din Salah Ud Din - 1 year ago 71
PHP Question

PHP Session lost when switching from to

Hy everyone,

If I visit my website with there is a login page, upon successful login I redirect user to instead of

I noticed that the session has been set but it is lost when switching from http:// to http://www,


setcookie('name', $data, time()+seconds, '/', "")

this work on both http:// and http://www
Please guide me

Answer Source

You could use session_set_cookie_params to set the cookie domain for the session to, or save the session id in your own cookies.

But I would suggest to create an redirect to the www or non-www version of your site in the htaccess

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download