Is there any way to redirect user to subdomain when he is using iPhone and then redirect to a different subdomain when he is using android, this all using php?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, you can use the $_SERVER global array to detect various information about a request such as the request headers. In particular, you can parse out the User Agent string to determine the browser connecting to your PHP application and redirect based on this information.
The PHP get_browser function documentation here has a good example:
Using the above you might craft your own functions like isAndroid or isIphone to detect the mobile device by the user agent string.
For reference, an iPhone user agent string will looks something like:
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543aAnd an Android’s user agent string will look like:
Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17Hope this helps!