Created
December 19, 2013 20:43
-
-
Save albertpak/8045958 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //a simple script to check user agents to detemine device type and or redirect | |
| //============================================== | |
| //get userangent string | |
| $userAgentraw = $_SERVER['HTTP_USER_AGENT']; | |
| //convert to lowercase to make search strings simplier | |
| $userAgent = strtolower ( $userAgentraw ); | |
| //check string for key words | |
| $ipad = strpos($userAgent, "ipad"); | |
| $android = strpos($userAgent, "android"); | |
| $msie10 = strpos($userAgent, "msie 10"); | |
| $msie8 = strpos($userAgent, "msie 8"); | |
| $touch = strpos($userAgent, "touch"); | |
| $mobile = strpos($userAgent, "mobile"); | |
| //double check windows tablet | |
| if($msie10 == true && $touch == true){ | |
| $winTablet = true; | |
| }else{ | |
| $winTablet = false; | |
| } | |
| //set urls for mobile & tablet | |
| $tabeltURL = "t.siteurl.com"; | |
| $mobileURL = "m.siteurl.com"; | |
| //logic to determine device type | |
| if ($mobile == true && $ipad == false) { | |
| $deviceType = "mobile"; | |
| //header("location: $mobileURL"); | |
| } elseif ($ipad == true || $android == true || $winTablet == true){ | |
| $deviceType = "tablet"; | |
| //header("location: $tabeltURL"); | |
| }elseif ($msie8 == true){ | |
| $deviceType = "ie8"; | |
| }else{ | |
| $deviceType = "desktop"; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment