I just started using browscap this week, and have been researching why I am not seeing the 'ismobiledevice' array key after calling browscap_get_browser.
To help figure out what is going on and see what browscap_get_browser is returning, I set up this debug code in my module:
$browser = browscap_get_browser();
drupal_set_message ('Browser attributes: <pre>' . print_r ($browser, 'true') . '</pre>');
Which returns this on the web site when I use FireFox/Iceweasel:
Array
(
[useragent] => Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20100101 Firefox/10.0.7 Iceweasel/10.0.7
[browser_name_pattern] => Mozilla/5.0 (*Linux*) Gecko/* Firefox/10.*
)
And I get the following when using my Samsung Epic 4G:
Array
(
[useragent] => Mozilla/5.0 (Linux: U; Android 2.3.6; en-us; SPH-D700 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
[browser_name_pattern] => Mozilla/5.0 (*Linux*Android 2.3*)*AppleWebKit/*(*KHTML, like Gecko*)*Version/4.0*Mobile Safari/*
)
Anyone can easily go to the site http://dev.army.com/ and see for yourself. I will leave it up until I figure this out or give up and figure out something else to detect mobile devices.
The good news is I believe the PHP Notice below shows the problem.
PHP Notice: unserialize(): Error at offset 0 of 1356 bytes in /usr/local/share/drupal/modules/browscap/browscap.module on line 179
I have tried using base64_encode as shown below to encode the data when imported and then base64_decode when fetching it from the db, but that did not seem to help.
In import.inc
...
// Insert all data about the current user agent into the database
db_query("INSERT INTO {browscap} (useragent, data) VALUES ('%s', %b)", $user_agent, base64_encode(serialize($e)));
And in browsecap.module
...
// Unserialize the user agent data found in the cache or the database
$properties = unserialize(base64_decode($user_agent_properties->data));
So, can anyone tell me what I am doing wrong? Given the vast number of modules and web sites using browscap successfully, I seriously doubt this is a browscap issue and I suspect I am going to feel like an idiot when I find out why the unserialize error is happening and/or how to retrieve the ismobiledevice value. ;-)
Thanks for your thoughts.
Comments
Comment #1
gregglesI'm unable to reproduce this problem and it seems nobody else has experienced it. Marking closed.