Solved

Use php to detect mobile device period

Posted on 2013-12-13
6
344 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
  • 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 109

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 109

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 109

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

821 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