I am struggling with code that redirects a user to other pages based on language detection. I found this code which looks promising as so far I have not had any luck from other posts on this website. My only question is related to the first line of code. What do I put in the "" part on first line?
<?php
$lc = ""; // Initialize the language code variable
// Check to see that the global language server variable isset()
// If it is set, we cut the first two characters from that string
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$lc = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
// Now we simply evaluate that variable to detect specific languages
if($lc == "fr"){
header("location: index_french.php");
exit();
} else if($lc == "de"){
header("location: index_german.php");
exit();
}
?>
<h2>Hello Default Language User</h2>
<h3><?php echo "Your 2-letter Code is: ".$lc; ?></h3>
When I run this code I get an error message:
Warning: Cannot modify header information - headers already sent by (output started at /home/m3418630/public_html/sumoresources/index.php:3) in /home/m3418630/public_html/sumoresources/index.php on line 12
Can anyone explain why this happens?
thanks