What are some potential pitfalls when using query strings in PHP for language switching on a website?

One potential pitfall when using query strings for language switching in PHP is that the language choice is exposed in the URL, which can lead to usability issues and potential security vulnerabilities. To solve this, you can store the language choice in a session variable instead of using query strings.

<?php
session_start();

if(isset($_GET['lang'])){
    $_SESSION['lang'] = $_GET['lang'];
}

// Default language
$lang = 'en';

if(isset($_SESSION['lang'])){
    $lang = $_SESSION['lang'];
}

// Use $lang variable to display content in the selected language
?>