redirect on mobile code example

Example 1: How to Redirect Website to a Mobile Version when Accessed on a Mobile Device

if (screen.width <= 800) {  window.location = "http://m.domain.com";}

Example 2: How to Redirect Website to a Mobile Version when Accessed on a Mobile Device

<?php
 $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 “](https://s3.amazonaws.com/woocms.woorank.com/2020/05/poor-mobile-optimization.png”;
  }
 ?>

Tags:

Misc Example