Function that changes the language of my site based on http_accept_language

Posted on 2008-11-18
Last Modified: 2012-05-05

My website is displayable in 2 languages, English and dutch, and I want to show the dutch language if the http_accept_language is present and set to dutch [nl-NL?], the attached code is my first attempt to do so, can someone improve this pls, it should display English in every other case if the http_accept_language is not set to dutch, or, do you know a better way to do this in php?
function ChangeLang(){

$Dutch = 'nl';

$Nl = 'lang/dutch.lang';

$En = 'lang/english.lang';

  if (strstr($_SERVER['HTTP_ACCEPT_LANGUAGE'],$Dutch)){



     else {




Open in new window

Question by:PeterdeB
    LVL 107

    Accepted Solution

    That code looks fine to me.  This is what my server presents:

    _ENV["HTTP_ACCEPT_LANGUAGE"] = en-us,en;q=0.5

    Be aware of variable scope since you are including these lang modules inside a function.

    Best regards, ~Ray

    Author Comment

    Ok thank you very much, I already had taken notice of the variable scope but thanks again
    LVL 107

    Expert Comment

    by:Ray Paseur
    Thanks for the points, and good luck with your project! ~Ray

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now