简体   繁体   中英

multilingual website using $_SESSION

My website has two languages: French and English. The solution I chose is working but is causing me trouble. I use session in order to keep a "clean" url which is the same in English and in France.

My solution:

To choose the language, I locate the user using IP, and if it is not in France, i set

 $_SESSION['language'] = "ENG"

Otherwise,

 $_SESSION['language'] = "FRA"

Then I includes my file words.php which contains all the text like this:

if( $_SESSION['language'] == "ENG")
{
   $word1 = "hello"
   $word2 = ....
}
else
{
   $word1 = "bonjour"
   $word2 = ....
}

Finally on my website, I have several echo $word1; .

To change language, I have a two links (one for each language) to a webpage language.php with a get parameter that just change the session variable and redirect to the webpage:

if($_GET['l']=="1")
{
    $_SESSION['language'] = "FRA";

    header('Location: ' . htmlspecialchars($_SERVER['HTTP_REFERER']));
}
elseif($_GET['l']=="2")
{
    $_SESSION['language'] = "ENG";
    header('Location: ' . htmlspecialchars($_SERVER['HTTP_REFERER']));
}

My problem: My main problem is that Google is indexing my website only in English ( guess because the IP of crawler is not in France?). In google.fr and google.com, my website is in English. What can I do to have the website indexed in both languages?

You must use additional folders for languages. You can use example.com/fr for French content and example.com/en for English content.

You can tell this website is multilingual and multiregional to Google crawler bots. Edit this html code for your purpose.

<link rel=”alternate” href=”http://example.com/en-gb” hreflang=”en-gb” />
<link rel=”alternate” href=”http://example.com/en-us” hreflang=”en-us” />
<link rel=”alternate” href=”http://example.com/en-au” hreflang=”en-au” />
<link rel=”alternate” href=”http://example.com/” hreflang=”x-default” />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM