Session is not supported between mysite.com and www.example.com

I use a session to maintain some variables between different pages on my site. Although it works great when switching from www.example.com/a to www.example.com/b, session variables are lost if I switch from example.com/a to www.example.com/b

Any idea how I can make sure the session is supported regardless of www or not www?

The website adds WWW as it moves to different pages, but pages are available without it. Therefore, if someone manually enters the address and omits this part, and then go to page b (by clicking the link or submitting the form), the session variables are lost.

+3
source share
3

- example.com www.example.com; , www.example.com, .

, 301: Moved Permanently , example.com ( , apache, .htaccess):

Redirect 301 http://example.com/ http://www.example.com/

:

Redirect 301 http://example.com/(.*) http://www.example.com/$1

, :

Options +FollowSymlinks
RewriteEngine on

rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

http://www.webconfs.com/how-to-redirect-a-webpage.php

+5

, cookie .example.com, www.example.com, session_set_cookie_params, 3 -

+2

Session ID is stored in a cookie. Cookies cannot be transferred from a subdomain to a subdomain (for example, www.somesite.com on somesite.com). You can change cookie settings with session_set_cookie_params () or in php.ini

0
source

Source: https://habr.com/ru/post/1770459/


All Articles