0

I have a page that hosts one or more iframes, all from same domain.

for the main page and for each iframe I have a different session name (session_name()) so I can keep track of them. I know the name of each session.

If I am in one session - how can I modify one of the other sessions?

I tried (the overkill) this:

$session = session_name();
session_write_close();
unset($_SESSION);
session_name("othersession");  //a session that was initialized via the iframe
session_start();
$_SESSION['test'] = "hello from other session";
session_write_close();
unset($_SESSION);
session_name($session);
session_start();

yet, when I look at the original session - the "hello.." message is there as well. Infact, its ONLY there and not in the othersession session..

What am I doing wrong? Thanks!

9
  • unset($_SESSION); - don’t do that. php.net/manual/en/function.session-unset.php: “Caution: Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal.” Commented May 27, 2021 at 8:20
  • Thanks, noted and fixed. But it didn't solve the problem. Commented May 27, 2021 at 8:28
  • 1
    Fiddling with multiple sessions at the same time is always tricky, and error-prone. Can you first of all explain the purpose of this in a bit more detail? What exactly does “so I can keep track of them” mean, what exactly do you need to do? Commented May 27, 2021 at 8:30
  • Hi CBroe - each iframe serves as a kinda of a component, keeping its own information as the JS calles for the backend script. They may use the same variable names but they will be kept at different sessions. Commented May 27, 2021 at 9:03
  • 2
    Don’t see why the amount of data stored in a session should constitute a problem per se. But if you want to keep following the approach with individual sessions, check if stackoverflow.com/a/3150579/1427878 helps. Commented May 27, 2021 at 9:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.