-2

On my website, I need to share vars $_SESSION with an other website based on the same VPS.

I already test it but the vars $_SESSION didn't pass to the other website. But the configuration of the $_SESSION location is the same.

What should I check ?

Sorry for my English, I am French :)

Matancy

jrswgtr
  • 2,187
  • 8
  • 22
  • 41
  • 3
    Do you access the other website with the same domain name? That is, is your web site example.com/mysite and the other site example.com/othersite? If not, what's your setup – Joni Mar 19 '19 at 12:36
  • https://stackoverflow.com/questions/9153716/sharing-session-variables-between-multiple-subdomains might help for same domain. – Sougata Bose Mar 19 '19 at 12:44
  • My website does not have the same domain or subdomain. – Mathéo Tichy Mar 19 '19 at 12:50

2 Answers2

1

The important thing is that you must have a shared resource to share sessions among different hosts - be it a SQL database, memcached, a NoSQL database, etc. that all servers can access. You then use session_set_save_handler to access the shared resource.

  • In many server configurations there is a shared `/tmp` location for session files. The problem (better said "security feature") is the same origin policy of cookies. – Quasimodo's clone Mar 19 '19 at 12:48
-1

Your $_SESSION vars are only available inside the server where you're working on. Try this on any .php page of your project with

session_start();
echo "<pre>";
print_r($_SESSION);
echo "</pre>"; 

to understand better the working of the $_SESSION vars;

Quasimodo's clone
  • 5,865
  • 2
  • 20
  • 40
Jaakko
  • 334
  • 1
  • 12
  • On the website the session works without problems. But when i go to an onther website hosted on the same VPS, the session will be different. – Mathéo Tichy Mar 19 '19 at 12:52
  • You have to resort to another alternative like SQL, such as the Quasimodo's clone suggested above; If it were possible to do as you wish, the $ _SESSION vars would be unsafe to use; – Jaakko Mar 19 '19 at 12:55