How to Detect Browser Language in PHP? Last Updated : 11 Sep, 2024 Comments Improve Suggest changes Like Article Like Report We can detect requesting browser's language using PHP's super global variable $_SERVER. It is a superglobal variable that holds information about headers, paths, and script locations. It is basically an associative array in PHP which has keys like SERVER_NAME, SERVER_ADDR, REQUEST_METHOD, etc. We can use HTTP_ACCEPT_LANGUAGE key to get the language of the browser. Syntax:$_SERVER['HTTP_ACCEPT_LANGUAGE']Output:en-US, en;q=0.9, hi;q=0.8, fr;q=0.7Example 1: In order to get the current language of the browser, we can use PHP's built-in substr function to get the first two letters of the string like- PHP <?php echo substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?> After running the above program you'll see the output as your current browser's language - enYou can test it by changing your browser's language. If you are on chrome you can go to chrome://settings/languages and choose a different language. Now run the above program again and you'll see the output as the newly chosen language. Example 2: If your website has different pages for different languages, you can use this method in order to redirect to the page according to the user's browser's language. php <?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); // Redirect browser header("Location: https://www.geeksforgeeks.org/" . $lang . "/index.php"); exit; ?> The above program will redirect to links like http://www.example.com/en/index.php Comment More infoAdvertise with us Next Article How to Detect Browser Language in PHP? frikishaan Follow Improve Article Tags : Technical Scripter Web Technologies PHP Technical Scripter 2019 PHP-Misc +1 More Similar Reads How to detect the browser language preference using JavaScript ? Detecting the language preferences of users can be very important for Websites or Web Apps to increase user interaction. In JavaScript, this task can be easily done by using the Languages property available for the navigator interface. The navigator.language and the navigator.languages property toge 2 min read How to detect HTML 5 is supported or not in the browser ? HTML 5 is the latest standard of HTML that includes many new changes and features. HTML 5 support can be detected by using three approaches:Method 1: Checking for Geolocation support: The Geolocation API was added in HTML5. It is used for identifying the user's location. The presence of this API cou 4 min read How to detect the version of a browser ? This article includes the basic theory and technique of browser detection in JavaScript-enabled web browsers. Description: Even though most of the scripts work on JavaScript-enabled web browser, there are certain things that is not going to work on some browsers i.e. they are browser dependent and i 4 min read How to create a PHP detection browser script ? A browser script is used to find the complete information of the web browser. A web browser is working on the hypertext transfer protocol and retrieves all the information on the internet and displays it on your desktop so that you can access all the things from anywhere. In this article, we will s 2 min read PHP get_browser() Function In this article, we will know to check whether the user's browser capability using the get_browser() function in PHP, along with understanding its implementation through the example. The get_browser() function in PHP is an inbuilt function that is used to tell the user about the browser's capabiliti 3 min read How to get complete current page URL in PHP ? In PHP. there is a superglobal variable that can provide you with the URL of the current working page. The $_SERVER is an inbuilt variable that can access the page URL, after that, you have to check that the URL is following which type of HTTP protocol. What is Superglobal? Superglobals are already 1 min read How to serve a page with content in multiple languages ? In this article, we will see how the page content can be served in multiple languages. We can set the language in the HTML document by setting the lang attribute in the code. By default, the specified language is English, but it can be changed at our convenience. There is a way to change the content 3 min read How to Translate a Web Page in Another Language? With the internet connecting people globally, encountering websites in languages you don't understand is increasingly common. That's why most web browsers offer built-in translation features to help you easily translate web pages. Web browsers use translation services to convert text on web pages to 3 min read Flask - Language Detector App In this article, we will see how we can detect the language of an entered text in Python using Flask. To detect language using Python we need to install an external library called "langdetect" and "pycountry". Let's see how to implement Flask Language Detector App, before implementation we will try 4 min read How to get a File Extension in PHP ? In this article, we will learn how to get the current file extensions in PHP. Input : c:/xampp/htdocs/project/home Output : "" Input : c:/xampp/htdocs/project/index.php Output : ".php" Input : c:/xampp/htdocs/project/style.min.css Output : ".css" Using $_SERVER[âSCRIPT_NAMEâ]: $_SERVER is an array o 2 min read Like