How can a PHP script be modified to allow for alternative language options based on user selection?

To allow for alternative language options based on user selection in a PHP script, you can use a combination of session variables and language files. When a user selects a language, store their choice in a session variable. Then, include the appropriate language file based on the selected language in your PHP script.

<?php
session_start();

// Check if user has selected a language
if(isset($_GET['lang'])){
    $_SESSION['lang'] = $_GET['lang'];
}

// Include language file based on user selection or default to English
if(isset($_SESSION['lang'])){
    include 'lang_'.$_SESSION['lang'].'.php';
} else {
    include 'lang_en.php'; // Default to English
}

// Use language variables in your script
echo $lang['welcome_message'];
?>