For months, I have been searching for a simple script that can redirect majority of all mobile users to my mobile friendly page. However, I could never seem to find a script that works and especially one that was free. I mean I almost gave up searching until I found someone who had the same problem as I and developed his own script. I guess you could say I was more fortunate than him, since I did not have to deal with the headaches of programming.
Therefore, for those of you who are like me and want a script that works. I suggest you cut and paste the following php script to your website and simply follow the instructions provided for you below:
Here are 3 basic steps for using this script:
1. Make certain that the page you are planning to redirect is a .php file.
2. Copy and paste the script to the top portion of your html code.
For example:
<Paste PHP Script Here>
3. Under the second line of the PHP script provided above, please replace "http://www.yourmobilepage.com/" with the mobile friendly page you created for your website.
If you have followed all 3 steps correctly then you have successfully added mobile redirect to your page. Otherwise, you may want to repeat steps 1, 2 and 3. However, if the problem continues you may want to look elsewhere for assistance. Simply for the fact, that my knowledge is very limited on this subject.
Thank you for understanding and Good luck!
Therefore, for those of you who are like me and want a script that works. I suggest you cut and paste the following php script to your website and simply follow the instructions provided for you below:
PHP Code:
<?php
if(checkmobile()) header("Location:http://www.yourmobilepage.com/");
function checkmobile(){
if(preg_match("/iphone/i",$_SERVER["HTTP_USER_AGENT"])) return false;
if(preg_match("/Trident/i",$_SERVER["HTTP_USER_AGENT"])) return false;
if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) return true;
if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) return true;
if(isset($_SERVER["HTTP_USER_AGENT"])){
if(preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) return false;
if(preg_match("/MSIE/i",$_SERVER["HTTP_USER_AGENT"])) return false;
$uamatches = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto");
foreach($uamatches as $uastring){
if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) return true;
}
}
return false;
}
?>
1. Make certain that the page you are planning to redirect is a .php file.
2. Copy and paste the script to the top portion of your html code.
For example:
<Paste PHP Script Here>
Code:
<Paste PHP Script Here> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
If you have followed all 3 steps correctly then you have successfully added mobile redirect to your page. Otherwise, you may want to repeat steps 1, 2 and 3. However, if the problem continues you may want to look elsewhere for assistance. Simply for the fact, that my knowledge is very limited on this subject.
Thank you for understanding and Good luck!
Comment