Log in

View Full Version : Fetch information and show on site.



Jack!
19-06-2011, 11:29 PM
Now, what I'm trying to do here is when someone visits the site from there android phone, what I want to do is display the Make, model, ROM Version and android version, I know the first two are possible, but from a quick Google search I found nothing on that topic, can anyone help me?

Oh, and you can see what I'm trying to do (but remember it does not actually work) at www.mobile.xerom.net

Basically, I want to fetch the info from the phone, and display it in the phone browser, on the website.

Homosexual
20-06-2011, 12:13 AM
The only way I can think of: get a users user agent, which is different for each Android device, then use strpos to dissect the string which gives make, model and Android version (unsure about ROM version?).

I haven't tested this, so be careful.



<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
$string = 'HTC_Wildfire';

$pos = strpos($useragent,$string);

if($pos === false) {
echo "Not a HTC Wildfire";
}
else {
echo "HTC Wildfire";
}
?>


The user agent gives out something like this:

Mozilla/5.0 (Linux; U; Android 2.1-update1; ar-qa; HTC_Wildfire_A3333 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17

Obviously, Android 2.1-update1 is the Android version. ar-ga is the language, HTC_Wildfire_A3333 is the phone make and model, and Build/ERE27 is the build.
:)

Jack!
20-06-2011, 08:55 AM
The only way I can think of: get a users user agent, which is different for each Android device, then use strpos to dissect the string which gives make, model and Android version (unsure about ROM version?).

I haven't tested this, so be careful.



<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
$string = 'HTC_Wildfire';

$pos = strpos($useragent,$string);

if($pos === false) {
echo "Not a HTC Wildfire";
}
else {
echo "HTC Wildfire";
}
?>


The user agent gives out something like this:

Mozilla/5.0 (Linux; U; Android 2.1-update1; ar-qa; HTC_Wildfire_A3333 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17

Obviously, Android 2.1-update1 is the Android version. ar-ga is the language, HTC_Wildfire_A3333 is the phone make and model, and Build/ERE27 is the build.
:)


How would I got about stripping that down and displaying it? What i'm thinking of doing is so they come on to the site, and there phone info is already displayed, for any phone, so what I was thinking is in the code, it picks up the information, sets it as a variable, then in the section where I want to display that info it is:


Model: <?php echo blah. ?>

Would that kind of thing work? Also how would you going around doing it, because honestly I have no idea :P

+Rep :)

Recursion
20-06-2011, 08:57 AM
The ROM version is impossible for you to gather, it's not sent in any header requests or anything.

Jack!
20-06-2011, 09:57 AM
The ROM version is impossible for you to gather, it's not sent in any header requests or anything.

Okay, what I might do then instead is a list of compatible roms it can fetch from the database, when it has the phone information from the user agent

Homosexual
20-06-2011, 01:47 PM
I've sent you a PM if you want to reply to it, I've started working on some code to do this so yeah :)

Want to hide these adverts? Register an account for free!