Jump to content

Detectare Limba (Browser)


play

Recommended Posts

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.