How can multiple sessions be managed within the same domain in PHP?

To manage multiple sessions within the same domain in PHP, you can use session_name() function to set different session names for each session. This allows you to store and retrieve session data separately for each session within the same domain.

// Start the first session
session_name('session1');
session_start();
$_SESSION['user_id'] = 1;

// Start the second session
session_name('session2');
session_start();
$_SESSION['user_id'] = 2;