How do you identify a user as using an iPhone?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do you identify a user as using an iPhone?
Hi
We want to redirect users to a smaller browser version of a web site for iPhone users.
How do you identify the users device as an iPhone??
Hope someone can help.
We want to redirect users to a smaller browser version of a web site for iPhone users.
How do you identify the users device as an iPhone??
Hope someone can help.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you identify a user as using an iPhone?
You can try using the "$_SERVER['HTTP_USER_AGENT']" together with the preg_match( ) to see if the word "iPhone" is found in the return string which describes the browser. I tried it on my iPhone and it worked just fine.
Check out the manual at: http://www.php.net/manual/en/reserved.v ... server.php
This is also possible via the JavaScript "navigator" object: http://www.w3schools.com/js/js_browser.asp
Hope this helps.
Code: Select all
preg_match("/iPhone/", $_SERVER["HTTP_USER_AGENT"]);This is also possible via the JavaScript "navigator" object: http://www.w3schools.com/js/js_browser.asp
Hope this helps.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you identify a user as using an iPhone?
Thanks - it does with FF's user agent. Just waiting to hear from a colleague with an iPhone.
Can the same be done for Blackberry and Android?
Can the same be done for Blackberry and Android?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you identify a user as using an iPhone?
I believe you can by using the $_SERVER["HTTP_USER_AGENT"]. Check out the link[s] below:
http://php.net/manual/en/function.get-browser.php
http://php.net/manual/en/function.get-browser.php
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you identify a user as using an iPhone?
Great I found it.
Also, if you have a friend who has one of those phones, I found it how easy it is to find the name you need.
My next question is how to question the AGENT twice in the same script:
I want to add if it is a "BlackBerry" too now. And then perhaps "Android". I'm sure you can just add them all in that preg_match, but how?
Also, if you have a friend who has one of those phones, I found it how easy it is to find the name you need.
My next question is how to question the AGENT twice in the same script:
Code: Select all
if (preg_match("/iPhone/", $_SERVER["HTTP_USER_AGENT"]))Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you identify a user as using an iPhone?
You should be able to use the array returned from the "get_browser( )" function and retrieve the "browser" value together with a "switch( ){ }" statement. Check out the link below to see what I mean:
http://www.tuxradar.com/practicalphp/16/5/0
Cheers and good luck to you.
http://www.tuxradar.com/practicalphp/16/5/0
Cheers and good luck to you.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you identify a user as using an iPhone?
No I don't need any of that - I just need to know how you say "is it iphone, or Android, or Blackberry... in that Preg Match query.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you identify a user as using an iPhone?
try something like:
Code: Select all
if (preg_match("/(iPhone|Blackberry|Android)/i", $_SERVER["HTTP_USER_AGENT"]))
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you identify a user as using an iPhone?
Perfect. I don't know if it is 'Android', but I know it is "BlackBerry" and it works great.
Thanks.
Thanks.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.