Undefined index: HTTP_ACCEPT_LANGUAGE

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Undefined index: HTTP_ACCEPT_LANGUAGE

Postby matiasdag » 22. July 2006 05:06

Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in htdocs\mysite\classes\lang.class.php on line 18
which contains:
Code: Select all
// Implements language negotiation

class lang_detect {
 
  // PUBLIC VARIABLES
 
  VAR $langs ;        // Counter for how many languages are supported
  VAR $lang_list ;    // Language List [lang,q] pairs
 
  // PRIVATE VARIABLES
  VAR $accept_lang ;   // Original HTTP_ACCEPT_LANGUAGES
 
  // PUBLIC INTERFACE
 
  function lang_detect() {
    // Constructor: sets values for initial workout
    $this->accept_lang = $GLOBALS["HTTP_ACCEPT_LANGUAGE"] ; // <-- HERE
    $this->lang_init() ;
    }



This happens after enabling mbstring settings in php.ini ... mbstring is required by php-gettext package (see http://community.apachefriends.org/f/viewtopic.php?p=80970#80970). This doesn't happen in the server where I'm hosting my site.
Any ideas?
matiasdag
 
Posts: 5
Joined: 13. July 2006 07:32

Postby Izzy » 22. July 2006 06:58

The default location of the php.ini file is xampp/apache/bin/php.ini

Also make sure your script is compatible with the version of php you are running on your server. Version 5 is not backward compatible so if you are running version 5 and your script is written for version 4 then you may have to change versions or make your script work with v5.

Check the version being used on your host's server and use the same version on your XAMPP server - phpinfo.php located in your webroot directory on both servers will give you a good comparison.
Good luck :)
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby matiasdag » 22. July 2006 07:12

Yes, I forgot to mention, the server uses PHP 4.4 and my box uses PHP 5. I've solved the problem replacing
Code: Select all
$this->accept_lang = $GLOBALS["HTTP_ACCEPT_LANGUAGE"] ;

with
Code: Select all
$this->accept_lang = getenv('HTTP_ACCEPT_LANGUAGE');

thanks izzy for your tip.

matias
matiasdag
 
Posts: 5
Joined: 13. July 2006 07:32

Postby Izzy » 22. July 2006 07:17

Thats the major flaw with php, it is not backward compatible and it should be. Not many scripting languages behave in this manner, thank goodness.

Really pleased for you that you have it all working now.
Best wishes Matias. :)
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby Wiedmann » 22. July 2006 14:33

Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in htdocs\mysite\classes\lang.class.php on line 18
Code: Select all
$this->accept_lang = $GLOBALS["HTTP_ACCEPT_LANGUAGE"] ; // <-- HERE

Then your client have not send the header "HTTP_ACCEPT_LANGUAGE" during this request.

BTW:
Instead of the $GLOBALS array, you may use the $_SERVER array:
Code: Select all
$this->accept_lang = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; // <-- HERE


replacing with
Code: Select all
$this->accept_lang = getenv('HTTP_ACCEPT_LANGUAGE');

Now, if your browser don't send this header you have a (bool) "false" in "$accept_lang". and a (string) "" if the header is send with an empty string. (BTW: this is not working on IIS)

An other solution is a condition and test if this header is set/not empty. e.g.:
Code: Select all
if (empty($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
    $this->accept_lang = '';
} else {
    $this->accept_lang = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; // <-- HERE
}



This happens after enabling mbstring settings in php.ini

There is no difference between with and without mbstring on by box when I test your class.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 130 guests