Skip to content

Instantly share code, notes, and snippets.

@mikewing94
Created October 24, 2019 19:22
Show Gist options
  • Save mikewing94/f9c0aaee1d3b8834024962e9aba9952d to your computer and use it in GitHub Desktop.
Save mikewing94/f9c0aaee1d3b8834024962e9aba9952d to your computer and use it in GitHub Desktop.
<?php
session_start();
// Start the session
//header file
$language = $_GET['lang'];
$languagestart = '?lang=';
$newlanguage = $languagestart.$language;
if((isset($language)) || (!empty($language))){
//new language
echo $newlanguage;
// Set session variables
$_SESSION["language"] = $newlanguage;
}
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $actual_link;
$a = '/?lang=';
if (strpos($a, $actual_link) !== false) {
$b = 1; //in current url
} else {
$b = 0; //not in current url
}
$new_full_link = $actual_link.$newlanguage;
//check if language is set but current page does not have language in URL
if (isset($_SESSION["language"]) && ($b == 1)){
header("Location: $new_full_link");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment