Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirect Loop during the language detection
    primarykey
    data
    text
    <p>People,</p> <p>I'm working on a function based on the HTTP_ACCEPT_LANGUAGE and when I tested, the browser displays a redirection loop. I investigated all the solution provided in other posts but doesn't work</p> <p><strong>Updated: I tried to do this first using the httaccess detecting the language and redirecting to the correct page using the proper page and lang variables but I found the same issue. The problem is that I used two variables: page ( to determine in which page is the user ) and lang ( proper language depending on the spoken language of the user ). But the first time when the user arrives to the site: both variables are null so the purpose of this is detect the browser language of the user and then redirect it to the proper url, in my case..... index.php?page=index&amp;lang=en for instance...</strong> </p> <p>I did this:</p> <pre><code>**init.php** $supportedLangs = array ( 'en-GB', 'en-US', 'es-ES', 'es-AR' ); $languages = explode ( ',', $_SERVER ['HTTP_ACCEPT_LANGUAGE'] ); detectBrowserLanguage($languages,$supportedLangs); **functions.php** function detectBrowserLanguage($languages,$supportedLangs) { foreach ( $languages as $lang ) { if (in_array ( $lang, $supportedLangs )) { // Set the page locale to the first supported language found switch ($lang) { case 'es-ES' : header ( "Location: index.php?pagina=inicio&amp;lang=es", TRUE, 301 ); exit (); break; case 'en-US' : header ( "Location: index.php?pagina=inicio&amp;lang=en", TRUE, 301 ); exit (); break; case 'en-GB' : header ( "Location: index.php?pagina=inicio&amp;lang=en", TRUE, 301 ); exit (); break; default : header ( "Location: index.php?pagina=inicio&amp;lang=es", TRUE, 301 ); exit (); break; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload