What are the best practices for passing language parameters in PHP when switching between different language versions of a website?

When switching between different language versions of a website in PHP, it is best practice to pass language parameters through the URL or session variables. This allows for easy retrieval of the selected language throughout the website and ensures that the correct language content is displayed to the user.

// Passing language parameter through URL
<a href="index.php?lang=en">English</a>
<a href="index.php?lang=es">Spanish</a>

// Retrieving language parameter
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'en';

// Setting language session variable
$_SESSION['lang'] = $lang;