FabioRicali.it

Redirect in base alla lingua del browser con php

by info@fabioricali.it on mag.16, 2010, under PHP

<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang) {
	case "it":
			header("location: it/");
		break;
	case "en":
			header("location: en/");
		break;
	default:
			header("location: en/");
		break;
}
?>

4 Comments for this entry

  • energia eolica

    Salve, vorrei indirizzare solo nel caso l’utente abbia una lingua differente dall’italiano. come si fa?

  • info@fabioricali.it

    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    if ($lang != “it”) {
    header(“Location: en/”);
    }

  • Luca B.

    Mmm… grazie per lo scriptino… ma se dovessi reindirizzare la medesima pagina con un parametro ad hoc a seconda della lingua?
    In questo caso credo vada in loop, no?
    Ciao,
    L

  • info@fabioricali.it

    < ?php
    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    switch ($lang) {
    case "it":
    header("location: it/?param=1");
    break;
    case "en":
    header("location: en/?param=2");
    break;
    }
    ?>

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...