Url Redirection Based on Operating System?

jutt29

Regular Member
Joined
Sep 10, 2010
Messages
313
Reaction score
65
Can Some please give me the script to redirect my MAC and Windows user to different Urls?
Thanks
 
Code:
<?php

$windows_url = 'http://www.microsoft.com/';
$mac_url     = 'http://www.apple.com/';
$other_url   = 'http://www.lemonparty.org/';

$user_agent = $_SERVER['HTTP_USER_AGENT'];

if(preg_match('/microsoft|window/i', $user_agent)) {
	header("Location: $windows_url", true, 301);
} elseif(preg_match('/mac|os x/i', $user_agent)) {
	header("Location: $mac_url", true, 301);
} else {
	header("Location: $other_url", true, 301);
}

?>

Pretty self explanatory really. Fill in your urls up the top and include it before the opening <head> tag on your page.
 
Nice script, quick question. Why would you want this kind of redirrect ?

Probably so you can show ads that are targeted to each operating system, eg. show Windows users some anti-virus shit and Mac users some other crapware like MacKeeper. You wouldn't necessarily have to redirect - you could just identify the user agent as belonging to a particular OS and then just show an ad for that platform in your normal page.
 
Back
Top