PHP: Using browscap.ini on shared host. - ini_set() failing
Asked Answered
M

2

9

I'm trying to use get_browser() , unfortunately my page is on a shared host, and I have no access to php.ini.

I have downloaded the latest version of browscap.ini and placed in my document root. I have then added the following:-

if (!ini_set('browscap', '/home/private stuff/browscap.ini')) {
echo "Failed to set browscap";
} else {
echo "browscap = [" . ini_get('browscap') . "]";
}
exit();

But this fails, (nb: the echo statement for the failed condition always shows [] - even if I didn;t have the browscap.ini file the setting should still show up in the ini_get.... shouldn't it?)

I have looked at the previous questions on this and they don't seem to help, any ideas?

Marchellemarcher answered 30/3, 2010 at 14:19 Comment(0)
P
12

I hadn't heard of this feature before, but in Googling around I came across phpbrowscap (previously at a this Google Code repo( which is a standalone class that you should be able to use in your hosted environment. The author supports many configuration files and the QuickStart (previously here) looks especially easy.

Puppetry answered 30/3, 2010 at 14:51 Comment(2)
Thanks Tony, I've followed your suggestion and now have phpbrowscap working - so that's great. Unfortunately it means that I will never learn why the ini_set() approach didn't work, but I guess life's too short.... thx jonMarchellemarcher
Just wanted to add my voice saying this worked like a charm! Great browser detection! (I initially wanted to use deviceatlas.com but its a memory hog and likely won't work on many of our client shared hosts)Delative
P
11

As per the PHP manual, 'browscap' is changeable only in the system php.ini and/or httpd.conf. You cannot set it at the script level.

Precipitin answered 30/3, 2010 at 18:9 Comment(1)
Do you mean by httpd.conf the .htaccess file?Invisible

© 2022 - 2024 — McMap. All rights reserved.