Jump to content

Recommended Posts

Posted

Salut, mai jos aveti un cod php care detecteaza limba din browser.

Este util atunci cand aveti un site in diferite limbi si vreti ca utilizatorul sa fie redirectionat in functie de ce limba foloseste in browser-ul sau!

<?php

function limba_browser() {

$cod = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);

$cod = explode(",", $cod['0']);

     return $cod['0'];

     }


$limba = limba_browser();


 echo "Am detectat limba $limba";


 if ( $limba == en) {

 ///puteti folosi un redirect catre versiunea in engleza a site-ului

 echo "<br />";

 echo "Limba ta e Engleza, vei fi redirectionat imediat";

 }


 else {

 echo "<br />";

 echo "Limba ta nu e Engleza, deci nu te redirectionez nicaieri";


 }


?>

De asemenea aveti si un demo:

http://46.102.253.142/test/test.php

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.