0

How do I redirect website from different user agent? for example I want to redirect website from following user agent

  1. from desktop: redirect to Link1

  2. from iphone: redirect to Link2

  3. from android: redirect to Link3

  4. from windows(say all versions): redirect to Link4

  5. other: redirect to Link4

How do I achieve this in php?

EDIT: actually I don't the way of using $_SERVER['HTTP_USER_AGENT']; for user agents that i had mentioned. I have checked the answers of stackoverflow regarding this but don't know how to use that.

kiran
  • 595
  • 10
  • 31

2 Answers2

1

You might find $_SERVER['HTTP_USER_AGENT'] useful

Here's a good example:

<?php
    if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod')){  
        header('Location: http://yoursite.com/iphone');
        exit();
    }
?>

OR if you wanted to go by browser, you might find get_browser() useful

Axiom
  • 852
  • 1
  • 9
  • 20
0

The following will give you the user agent of someone connecting to you.

$_SERVER['HTTP_USER_AGENT'];

You might want to consider taking a look at this. Simplest way to detect a mobile device

Community
  • 1
  • 1
VJamie
  • 616
  • 3
  • 14