1

I'm currently working on an electron app on the client side, and an apache server for the backend.
This means that the app and the server are not on the same domains and the php files are called via jsonp (this is on a private network).
My problem is that I cannot set $_SESSION and $_COOKIES as the "calls" are made with jsonp and that the server is making a new session for each one : when i output the session_id() it is different everytime.

To be clear this is what I mean as json call (done in electron) :

var s = document.createElement("script");
s.src = "example.com/user.php?id="+username;
document.body.appendChild(s);

This php file echo connect(...)and the function connect is defined in the same document that creates the script.

What I want is to keep the session that the call as made.
I've thought of the following solutions :

  • Make an entry in the database with the data I wanted to have in $_SESSION
  • Get the session_id() and then set it in my other sessions with session_id($session)

Are there other solutions ? Which one would be better ?
Any feedback is appreciated !

  • https://stackoverflow.com/questions/676846/do-ajax-requests-retain-php-session-info – Script47 Jul 30 '18 at 10:22
  • In your table, make sure you can reference the user ID with the session ID and what happens if the same account signs in twice? How do you manage that? – Script47 Jul 30 '18 at 10:23
  • @Script47 This is cross-domain, I can't make AJAX calls as your link suggest (AJAAX is "same-origin policy"). For the table a new session would be made each time so the other sign in would overwrite the other one, but it wouldn't be a problem. – BatteryHorse Jul 30 '18 at 10:27

0 Answers0