Solved

Use php to detect mobile device period

Posted on 2013-12-13
6
346 Views
Last Modified: 2013-12-13
I was wondering is there a way to use php to detect a mobile device period?

I fixed something with the iPhone and I need to just be able to detect any mobile device.

Thank you,
Brian
0
Comment
Question by:burnedfaceless
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 39717396
This doesn't seem to be possible, as you can't access to client properties from server. However, you can pass some kind of parameter on the URL. For example you can make your Android device call this URL:

http://myurl.com/myfile.php?device=Android

and make the call from your iPhone device this way:

http://myurl.com/myfile.php?device=iPhone

Or maybe just use one and assume that if this argument isn't present then assume the other.

Then on PHP you should do something like this:

if ($_GET['device']=='iPhone) {
   // Put the code for iPhone case here
}
else
{
   // Put the code for Android case here
}

Open in new window

Hope it helps. Regards.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39717401
Didn't we cover this recently?  You were going to make a collection of HTTP_USER_AGENT values, right?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39717404
you can't access to client properties from server
Actually you get whatever the client sends in the request.  This usually includes some very useful information which is present in $_ENV and/or $_SERVER arrays.  PHP creates these arrays before your script gets control.  You can see what is in there with var_dump($_SERVER);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:burnedfaceless
ID: 39717558
I was wondering if there was an easier way.

The iPhone form distortion was brought about by css media queries I think they don't interact with bootcamp well on iPhone.

9/10 Android devices run it properly but for that one user we're a bush-league site.

So I will use header or whatever and have separate mobile and desktop pages.

Unless there's a better route.
0
 

Author Comment

by:burnedfaceless
ID: 39717574
Ultimately css media queries are limited so I'm agreeing with Ray on using php.

The bootstrap template is forgiving but if you work out of it don't add other css queries. Android is too fragmented and the iPhone has its own issues.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39718031
You can use header() to redirect to another script or you can just load the script directly in PHP, perhaps with include() and run the script without redirection.  Something conceptually like this...

if (iphone) include('iphone_script.php')
elseif (android) include('android_script.php')
elseif (desktop) include('desktop_script.php')
else trigger_error('UNKNOWN BROWSER", E_USER_ERROR);

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question