Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.10.5
  • Fix Version/s: 1.10.7
  • Component/s: Zend_Locale
  • Labels:
    None

Description

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);

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Zijin Huang added a comment -

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: http://www.php.net/manual/en/function.getenv.php

Show
Zijin Huang added a comment - 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: http://www.php.net/manual/en/function.getenv.php
Hide
Thomas Weidner added a comment -

Tested with new information and agreed

Show
Thomas Weidner added a comment - Tested with new information and agreed
Hide
Thomas Weidner added a comment -

Fixed with r22529

Show
Thomas Weidner added a comment - Fixed with r22529
Hide
Maciej Hołyszko added a comment -

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 (+http://search.msn.com/msnbot.htm)" or "Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; ...)" or "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

Show
Maciej Hołyszko added a comment - 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 (+http://search.msn.com/msnbot.htm)" or "Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; ...)" or "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
Hide
Thomas Weidner added a comment -

Not reproduceable because there IS a check with isset()

Show
Thomas Weidner added a comment - Not reproduceable because there IS a check with isset()
Hide
Maciej Hołyszko added a comment -

Yes, it is there now indeed, because it was fixed in http://framework.zend.com/issues/browse/ZF-10114. Thank you.
I guess I'd better create a separate issue next time instead of commenting already closed one.

Show
Maciej Hołyszko added a comment - Yes, it is there now indeed, because it was fixed in http://framework.zend.com/issues/browse/ZF-10114. Thank you. I guess I'd better create a separate issue next time instead of commenting already closed one.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: