Language-detection PHP script
On principle the code is sound except for one issue: you do not check if the language is "valid". This raises some questions:


How will your localization code behave if I added a lang parameter with the value "foobar"?
How will it behave if I try to do an SQL injection using the parameter value?


In both cases, the sane outcome would be to default to your "main" language, which would probably be hardcoded in your application.

Another issue you may want to consider is that nobody knows that there is an Accept-Language header and how to use it, so using that as a source of the user's preferred locale is not recommended:


  It is not a good idea to use the HTTP Accept-Language header alone to
  determine the locale of the user. If you use Accept-Language
  exclusively, you may handcuff the user into a set of choices not to
  his liking.


In your shoes I would totally scrap using $_SERVER['HTTP_ACCEPT_LANGUAGE'] (IMHO it's useless in practice). If you want to go the extra mile and auto-detect the user's locale, use an IP database (I have used MaxMind GeoIP in the past myself) or the upcoming W3C geolocation spec.