I want to be able to switch back and forth between sessions in php. Here is my current code:
What you need to use is session_id() instead of session_name()
", print_r($_SESSION, 1), "";
session_write_close();
session_id("session2");
echo session_id();
session_start();
$_SESSION["name"] = "2";
echo "", print_r($_SESSION, 1), ""; session_write_close(); session_id("session1"); echo session_id(); session_start(); echo "
", print_r($_SESSION, 1), ""; session_write_close(); session_id("session2"); echo session_id(); session_start(); echo "
", print_r($_SESSION, 1), "";
This will print:
session1
Array
(
[name] => 1
)
session2
Array
(
[name] => 2
)
session1
Array
(
[name] => 1
)
session2
Array
(
[name] => 2
)
session_id is an identifier for a session, which helps in distinguishing sessions. session_name is only a named alias for the current session