Mobile Redirect Script

Started on the old forum in January 2010 · view the original in the archive · old links redirect here

7 replies · 1,179 views · started 16 years ago · 1 min read

4 participants
bOrN2pwn Developer · 230 posts #1

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:

<?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;
} 

?>

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>

<Paste PHP Script Here>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
          <html>
  1. 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!

BakGat

class Counter {
public:
  void Count();
  int  ReadDisplay();
private:
  int  CurrentCount;
};

External image (may be gone) External image (may be gone) External image (may be gone)

Back up my hard drive? How do I put it in reverse? http://www.hackthissite.org Profile…

wapmaster2 Developer · 114 posts #3

and if you want redirect your web page on other URL then

<?php if(checkmobile()) header("Location:http://yourdomain.com/mobile/index.php"); 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; } ?> <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/WEB/index.html">

🌹 JUST JOIN FOR FUN ! **[url]http://wapmaster2.com**

CreativityKills Lead · 833 posts #6

I dnt tink it cud be as precise as wurfl. WURFL is a project, which means updates, fixes and support, nt 2 mention a up-to-par device database. If u wana hook up a huge or serious project use wurfl, otherwise, if its a lava type site dnt bother wasting ur time, use this one by b0rn2pwn 🙂

haraldl Junior · 33 posts #8

RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR] RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC] RewriteCond %{HTTP_USER_AGENT} !macintosh [NC] RewriteRule ^(.*)$ http://yourdomainherer.com/index.html [L,R=302]

it works too 😉

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close