Skip to main content

Simple PHP Mobile Website Redirect Code

By May 28, 2013March 5th, 2021Technology

Here is a simple PHP mobile website redirect that will work for most PHP websites in a linux environment. The even works when added to the header.php file in most WordPress themes.

$iphone = strpos($_SERVER[‘HTTP_USER_AGENT’],”iPhone”);
$android = strpos($_SERVER[‘HTTP_USER_AGENT’],”Android”);
$palmpre = strpos($_SERVER[‘HTTP_USER_AGENT’],”webOS”);
$berry = strpos($_SERVER[‘HTTP_USER_AGENT’],”BlackBerry”);
$ipod = strpos($_SERVER[‘HTTP_USER_AGENT’],”iPod”);

if ($iphone || $android || $palmpre || $ipod || $berry == true) 
    echo “<script>window.location=’'</script>”;