ZF-10005: Zend_Locale getenv(HTTP_ACCEPT_LANGUAGE) Windows ISAPI - Autodetection of Locale has been failed!


Does Zend_Locale fully support PHP running on Windows IIS ISAPI mode?

"getenv(HTTP_ACCEPT_LANGUAGE)" returns null with php running on Windows IIS ISAPI mode which causes the following Exception:

Fatal error: Uncaught exception 'Zend_Locale_Exception' with message 'Autodetection of Locale has been failed!'

Would it be better if getenv() can fall back to using $_SERVER variables in case getenv is not available?

To reproduce, simply create a file with the following (include Zend/Locale or Autoloader first of course):

$locale = new Zend_Locale(Zend_Locale::BROWSER);


Closing as non-issue

This exception just notes that the browser does not send an language header.

And that in your environment even the system's locale can not be found. This exception is only thrown when no locale can be retrieved, wether within the browser, nor the environment. And when additionally the default fallback locale has been erased manually.

So the generic problem is not ISAPI but that even php's setlocale() method does not return any value and that default has been erased manually.

My broswer is correctly sending the language header. I can confirm this as I was migrating the code from Linux server to a Windows server. Same test code works fine on Linux server (using the same browser).

Please note that I have "Zend_Locale::BROWSER" in the constructor ( $locale = new Zend_Locale(Zend_Locale::BROWSER); ) which means I only want to check for browser language setting, it should not fall back to environment language settings anyway. It's not related to setlocale or locale not set in the server/php environment.

The problem really comes down to the getBrowser() function in Locale.php on Windows IIS ISAPI mode where getenv('HTTP_ACCEPT_LANGUAGE') is called. getenv('HTTP_ACCEPT_LANGUAGE') function call returns null even when the correct header is sent. In fact, getenv() returns null for whatever server variables I try to get. However $_SERVER["HTTP_ACCEPT_LANGUAGE"] is available, so my question is whether getenv('HTTP_ACCEPT_LANGUAGE') can fallback to use $_SERVER["HTTP_ACCEPT_LANGUAGE"] just for Windows IIS ISAPI mode?

Looking at the PHP manual, it appear to suggest that in CGI mode, getenv will work:

Tested with new information and agreed

Fixed with r22529

I think this fix is not full - it should be wrapped with isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) because this variable is not always available - for example when web crawlers visit our page. When we updated to r22529 of ZF 1.10 branch we now get a lot of PHP notices: *Undefined index HTTP_ACCEPT_LANGUAGE* at *Zend/Locale.php:430* from user-agents like "msnbot/2.0b (+" or "Feedfetcher-Google; (+; ...)" or "Mozilla/5.0 (compatible; Googlebot/2.1; +"

Not reproduceable because there IS a check with isset()

Yes, it is there now indeed, because it was fixed in Thank you. I guess I'd better create a separate issue next time instead of commenting already closed one.