Solved

Use php to detect mobile device period

Posted on 2013-12-13
6
345 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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