📜 ⬆️ ⬇️

Cross Domain Cookies

Consider the case when you have several subdomains on the same server. We need the session to be stored on the server and read by all scripts on different subdomains. This can be done in several ways:
1) Rearrange the domain of cookies for the session before the session:
session_set_cookie_params(0 , '/', '.site.ru');<br>session_start();<br> 2) Rearrange the cookie after creating the session, and call its name before each session.
<br>if (isset($_COOKIE['PHPSESSID'])) {<br> setcookie("PHPSESSID", $_COOKIE['PHPSESSID'], 0, "/", '.site.ru');<br> session_name($_COOKIE['PHPSESSID']);<br>} else {<br> session_start();<br>}<br>?><br> 3) Open php.ini and explicitly specify there
session.cookie_domain = '.site.ru'; The latter option will work for different sites that are not subdomains of the same server.

')

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


All Articles