-2

just want to ask about the language on your site, i want develop a sample program in PHP wherein the user can choose the website language or is it possible if your site can automatically detect the user's country and auto convert the language?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
siaobukol
  • 1
  • 2
  • see http://stackoverflow.com/questions/10175658/is-there-a-simple-way-to-get-the-language-code-from-a-country-code-in-php – Bhavesh G Feb 08 '14 at 13:17

1 Answers1

0

Paste this before the <html> tag:

<?php
session_start();
?>

and this where you want your page or language menu:

<?php

if(isset($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
if($lang=='en')
{
    //you can change this action, it is only an example
    echo '<a href="changelang.php">Change your language / Zmień swój język</a>';
    echo 'This page is in English!';

}

if($lang=='pl')
{
    echo '<a href="changelang.php">Change your language / Zmień swój język</a>';
    echo "Ta strona jest po Polsku!";

}

}
else
{
header('Location: changelang.php');

}

?>

Now create changelang.php file:

<?php
session_start();
if(isset($_GET['lang']))
{
 $_SESSION['lang']=$_GET['lang'];
 header('Location: index.php');

}
?>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Choose your language</title>
</head>
<body>
Choose your language / Wybierz swój język </br>
 <a href="?lang=en">English</a></br>
 <a href="?lang=pl">Polski</a> </br>


</body>
</html>
alufers
  • 134
  • 2
  • 10