|
Jan 24
2011
|
Browser RedirectsPosted by bohemia in Untagged |
|
Using PHP to redirect pages based on browser can make life simpler in some circumstances. The following samples below show various redirects for various browers.
if(preg_match("/opera/i",$_SERVER['HTTP_USER_AGENT']))
die(header("Location: http://getfirefox.com"));
?>
<?php
if(preg_match("/chrome/i",$_SERVER['HTTP_USER_AGENT']))
die(header("Location: http://getfirefox.com"));
?>
<?php
if(preg_match("/safari/i",$_SERVER['HTTP_USER_AGENT']))
die(header("Location: http://getfirefox.com"));
?>
<?php
if(preg_match("/MSIE/i",$_SERVER['HTTP_USER_AGENT']))
die(header("Location: http://getfirefox.com"));
?>
<?
$redirect="http://www.redirecturlputhere.net";
if(preg_match('/Firefox/',$_SERVER['HTTP_USER_AGENT']))!
=1) header("Location: ".$redirect);
?>
