سؤال

I am trying to use PHP's built-in function get_browser(). I followed the instructions in this useful post, but I'm still getting the error

browscap ini directive not set.

I downloaded the php_browscap.ini file and moved it into the same directory as my .htaccess file, so that its location is home/hostname/subdomain/php_browscap.ini Since I do not have access to my php.ini file, I am trying to edit the browscap property using .htaccess. This is what I entered:

php_value browscap home/hostname/subdomain/php_browscap.ini

I don't know if it matters, but below that there's some Rewrite Engine code.

As forementioned, I am still getting the error above. What did I do wrong?

Thanks.

هل كانت مفيدة؟

المحلول

Do a phpinfo() to understand your PHP runtime config. If your system is configure as "CGI/FastCGI" then it is probably running suPHP as the PHP initiator. In this case you can specify your own php.ini file. By default suPHP looks in the script directory but you can override this by the following directive in your .htaccess file:

suPHP_ConfigPath (expects a path name)

This option tells mod_suphp which path to pass on to the PHP-interpreter (by setting the PHPRC environment variable). Do NOT refer to a file but to the directory the file resists in.

E.g.: If you want to use "/path/to/server/config/php.ini", use "suPHP_Config/path/to/server/config".

If you don't use this option, PHP will use its compiled in default path. Also you must use a properly formed path in your browsercap directive e.g.

browscap="/home/hostname/subdomain/php_browscap.ini"

(Note the leading /)

Addendum

I've just check and the Dreamhost shared hosting plan uses suEXEC. With suEXEC you can normally override the php.ini patch by copying the system php.ini (phpinfo() tells you where to find this) into a private directory, say _private as well as the browsercap.ini then adding

SetEnv PHPRC /home/hostname/_private

to your .htaccess file. If this doesn't work then the issue is specific to Dreamhost's suEXEC config and you need to ask this Q on http://discussion.dreamhost.com/

نصائح أخرى

The browscap PHP value has a changeable mode of PHP_INI_SYSTEM meaning it can only be set in php.ini or httpd.conf (not .htaccess).

There are two potential problems here.

  1. Perhaps your host does not allow you to override ini settings in the .htaccess file.
  2. Maybe browscap does not like the path you have provided. Try:

    php_value browscap /home/hostname/subdomain/php_browscap.ini
    

    And ensure that permissions on that file allow the web user to read it.

If you are on a shared hosting and do not have access to the system php.ini then you can use the following standalone replacement of php's native "get_browser()" implementation.

https://github.com/garetjax/phpbrowscap

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top