Register FAQ/Rules Forum Spy Search Today's Posts Mark Forums Read

Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate.

 
Go Back   Mac Forums > Special Interests > Web Design and Development
TouchArcade.com - iPhone Game Reviews and News

Reply
 
Thread Tools Search this Thread Display Modes
Old May 31, 2006, 02:36 PM   #1
nerveosu
macrumors member
 
Join Date: Sep 2001
Here is how to detect a mobile device using php.

For anyone who wants to use it..

This is a way to detect with php if a visitor to your web site is using a mobile device browser.. it works. If you have a mobile device that this doesn't detect, all you have to do to add it is to find a unique bit of identifying information in your device's user agent and stick it in the list of mobile devices in this code.

------------

<?php


/* detect mobile device*/
$ismobile = 0;
$container = $_SERVER['HTTP_USER_AGENT'];

// A list of mobile devices
$useragents = array (

'Blazer' ,
'Palm' ,
'Handspring' ,
'Nokia' ,
'Kyocera',
'Samsung' ,
'Motorola' ,
'Smartphone',
'Windows CE' ,
'Blackberry' ,
'WAP' ,
'SonyEricsson',
'PlayStation Portable',
'LG',
'MMP',
'OPWV',
'Symbian',
'EPOC',

);

foreach ( $useragents as $useragents ) {
if(strstr($container,$useragents)) {
$ismobile = 1;
}
}



if ( $ismobile == 1 ) {
echo "<p>mobile device</p>";
echo $_SERVER['HTTP_USER_AGENT'];
}

?>

Last edited by nerveosu : May 31, 2006 at 02:51 PM.
nerveosu is offline   Reply With Quote
Old Oct 10, 2008, 12:25 PM   #2
beradrian
macrumors newbie
 
Join Date: Oct 2008
You can see here a few other (better) methods to detect a mobile device: http://beradrian.wordpress.com/2008/...e-recognition/
beradrian is offline   Reply With Quote
Old Oct 10, 2008, 01:14 PM   #3
angelwatt
macrumors 601
 
Join Date: Aug 2005
Location: Dayton, OH
Quote:
Originally Posted by beradrian View Post
You can see here a few other (better) methods to detect a mobile device: http://beradrian.wordpress.com/2008/...e-recognition/
How is that better? Looks more complicated to me.
angelwatt is online now   Reply With Quote
Old Nov 18, 2008, 06:58 PM   #4
qwertydesign
macrumors newbie
 
Join Date: Nov 2008
there is also a web service out there that provides GEO location as well as handset information real time.

There are a few out there that do this, but we use handsetdetection.com when developing new sites for clients.
qwertydesign is offline   Reply With Quote
Old Nov 18, 2008, 07:36 PM   #5
web_god61
macrumors member
 
Join Date: May 2004
wouldn't
Code:
in_array($_SERVER['HTTP_USER_AGENT'], $useragents)
make more sense than a for loop?
__________________
Macbook C2D
iPod Nano 4Gb
web_god61 is offline   Reply With Quote

Reply

Mac Forums > Special Interests > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:22 PM.

Mac News | Mac Rumors | iPhone Game Reviews | iPhone Apps

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 2002-2009, MacRumors.com, LLC