Skip to main content
edited title
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

My language Language-detection PHP script. How can I improve it?

edited tags
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481
deleted 119 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

My language detection php-detection PHP script. How can I improve it?

I'm working on a webpage with language detection, and I have the following script so far (it's simple), so how could I improve it? I. I still haven't done the user detection, so it's not available to find the user language (yet), but this will be easily implemented. ThoughtThough I'm not asking for that, I'm asking for other ways to improve this code. So far as I've tested it, it's bug-free, but I want it to be bulletproof by experts like you. How can I improve it? (oror expand it?)

Code:

//LANGUAGES
//Language detection
if ( !empty($_POST['lang']) )
    {
    $Lang = $_POST['lang'];
    $_SESSION['lang']= $_POST['lang'];
    }
else
    {
    if ( !empty ($_SESSION['lang']))
        $Lang = $_SESSION['lang'];
    else
        $Lang = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    }

//After this, $Lang will have the webpage preference

sorry for my English and thank you for reading this!

My language detection php script. How can I improve it?

I'm working on a webpage with language detection, and I have the following script so far (it's simple), so how could I improve it? I still haven't done the user detection, so it's not available to find the user language (yet), but this will be easily implemented. Thought I'm not asking for that, I'm asking for other ways to improve this code. So far as I've tested it, it's bug-free, but I want it to be bulletproof by experts like you. How can I improve it? (or expand it?)

Code:

//LANGUAGES
//Language detection
if ( !empty($_POST['lang']) )
    {
    $Lang = $_POST['lang'];
    $_SESSION['lang']= $_POST['lang'];
    }
else
    {
    if ( !empty ($_SESSION['lang']))
        $Lang = $_SESSION['lang'];
    else
        $Lang = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    }

//After this, $Lang will have the webpage preference

sorry for my English and thank you for reading this!

My language-detection PHP script. How can I improve it?

I'm working on a webpage with language detection and I have the following script so far (it's simple). I still haven't done the user detection, so it's not available to find the user language (yet), but this will be easily implemented. Though I'm not asking for that, I'm asking for other ways to improve this code. So far as I've tested it, it's bug-free, but I want it to be bulletproof. How can I improve or expand it?

//LANGUAGES
//Language detection
if ( !empty($_POST['lang']) )
    {
    $Lang = $_POST['lang'];
    $_SESSION['lang']= $_POST['lang'];
    }
else
    {
    if ( !empty ($_SESSION['lang']))
        $Lang = $_SESSION['lang'];
    else
        $Lang = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    }

//After this, $Lang will have the webpage preference
Post Migrated Here from stackoverflow.com (revisions)
Source Link
Loading