kiran
kiran

Reputation: 641

redirect website from different user agent in php

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.

Upvotes: 0

Views: 2392

Answers (2)

VJamie
VJamie

Reputation: 636

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

Upvotes: 0

Axiom
Axiom

Reputation: 902

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

Upvotes: 1

Related Questions