What are the potential issues with PHP sessions being appended multiple times to URLs?

Appending PHP sessions multiple times to URLs can cause issues such as session fixation attacks and unnecessary bloating of URLs. To solve this issue, we can check if a session ID is already present in the URL before appending it again.

// Check if session ID is already present in the URL
if (!isset($_GET[session_name()])) {
    // Append session ID to the URL
    $url = $_SERVER['REQUEST_URI'];
    if (strpos($url, '?') !== false) {
        $url .= '&' . session_name() . '=' . session_id();
    } else {
        $url .= '?' . session_name() . '=' . session_id();
    }
    header('Location: ' . $url);
    exit();
}