Solved

Use php to detect mobile device period

Posted on 2013-12-13
6
341 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
Comment Utility
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 108

Accepted Solution

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

Expert Comment

by:Ray Paseur
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Closing Comment

by:burnedfaceless
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now