What are the best practices for using sessions in PHP to store language preferences?

When storing language preferences using sessions in PHP, it is important to set the language preference in the session when the user selects a language. This preference can then be used throughout the session to display content in the selected language. A best practice is to create a separate PHP file to handle language preferences and include it in all pages where language selection is needed.

<?php
session_start();

// Set language preference in session
if(isset($_GET['lang'])) {
    $_SESSION['lang'] = $_GET['lang'];
}

// Include language preferences file
include 'language_preferences.php';

// Use the selected language preference throughout the session
echo $lang['welcome_message'];
?>