Developer Resources

» Web to Mobile Redirect Code


 

Redirect to Mobile

Below are a few different implementations of web-to-mobile code. As a developer, you should use this code on your web page so that mobile users are directed to your WAP site, and web users stay on your web site.

TOP PRODUCER USERS: Top Producer supports our redirect code! To implement please call us at 877.720.0988.


PHP Implementation: Include Detect File (RECOMMENDED)

Download the zip file, and paste the contents of the usage.txt file into the very top of your index.php page. Dont forget to change the URL to your Mobile URL.

DOWNLOAD CODE

Place the MCC_phone_detect_inc.php file in the root of your web directory.


Would you like to be notified when this code is updated? Email us!


Wordpress Simple Implementation

Wordpress users - if you do not have access to your source code or are having problems implementing the redirect code, you can try using WPTap Mobile Detector plugin. MCC has no affiliation with WPTap, however some of our clients have used it and it offers a simple way to redirect users. After installing the plugin, go to plugin settings (typically at the bottom of your left menu in admin) be sure to enter your mobile website address for all available handsets. The above PHP implementation is preferred as it offers a far more extensive library of handsets, but the WPTap Mobile Detector is a fair alternative for users seeking a quick and code-free way to redirect mobile traffic.


Javascript Implementation

Javascript redirect is not preferred as it only works on handsets with javascript enabled, but is easiest to implement and will cover the majority of handsets, especially smartphones. Also, this code will work with virtually any page type - php, aspx, asp, html, htm, etc.

Platform users: If you use a Real Estate platform (including WordPress/TypePad, etc) you should be able to use this code. Either place it at the top of your page templates, or in some cases you can place it inside your additional META fields in your platform.

Place the following snipped of code either in the HEAD of your document (between the <head> and </head> tags), or just below the <body> tag. Don't forget to put your mobile URL in the two spots below!

<script language="javascript" type="text/javascript">
function doRedir() {
if(navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/1000/i) || navigator.userAgent.match(/9000/i) || navigator.userAgent.match(/m180/i) || navigator.userAgent.match(/t849/i) || navigator.userAgent.match(/i987/i) || navigator.userAgent.match(/tablet/i) || navigator.userAgent.match(/p100/i) || navigator.userAgent.match(/t849/i) || navigator.userAgent.match(/i800/i)) {
// device is a tablet or pc
} else if (navigator.userAgent.match(/(opera mini|ipod|iphone|up.browser|up.link|mmp|symbian|smartphone|
midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo|nokia|blackberry|pre\/0.1|android)/i)) {
// ua match
location.replace("http://INSERT YOUR MOBILE URL");
} else if (screen.width <= 699) {
// width match
location.replace("http://INSERT YOUR MOBILE URL");
} }
var ref=document.referrer.toLowerCase();
if(ref.indexOf("mccid.com") > -1) {
// dont go anywhere
} else {
doRedir();
}
</script>

Note: The script above allows 'view full site'. Simply link your view full site button or text to your website and users will be able to view your full website.


ASP.NET/ ASP Implementation: Include Detect File (in development)

PREFERRED CODE:

Download the zip and use the ASPX file included. DOWNLOAD CODE

Remember to change the Mobile URL to your mobile URL.

ALTERNATE CODE:

The following code can be implemented into your asp.net or ASP home page. This is a basic redirect.

string strUserAgent = Request.UserAgent.ToString().ToLower();
if (strUserAgent != null)
{
if (Request.Browser.IsMobileDevice == true ||
    strUserAgent.Contains("iphone") ||
    strUserAgent.Contains ("blackberry") ||
    strUserAgent.Contains("mobile") ||
    strUserAgent.Contains("windows ce") ||
    strUserAgent.Contains("opera mini") ||
    strUserAgent.Contains("palm"))
         {
         Response.Redirect("http://YOURMOBILESITE.mccid.com");
         } 
}

Remember to put your mobile URL at the bottom in the Response.Redirect line of code.


Would you like to be notified when this code is updated? Email us!

Developers: If you use this code and improve or enhance it, please email TheOtherJohn@mobilecardcast.com and we'll update our code with your changes. Thanks!


External Resources

Here are some sites that provide alternate redirect code, that we've found helpful:
http://detectmobilebrowser.com/ | http://handsetdetection.com | http://detectmobilebrowsers.mobi/ | http://wordpress.org/extend/plugins/wptap-mobile-detector/

Note: Mobile Card Cast is not affiliated with any of these sites, nor do we guarantee their safety or functionalty.


The code below should work, but is not recommended or supported by Mobile Card Cast as many devices do not have javascript enabled, rendering the code below useless.

 

Simple Javascript Implementation (no longer recommended)

This is the simplest implementation. It requires no PHP or ASP code, and is environment-indifferent, for the most part.

Copy the below code within the HEAD tags of your web page:

<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "http://yourmobiledomain.mccid.com";
}
//-->
</script>



 

 
 
Copyright 2011 Mobile Card Cast, Inc. All Rights Reserved. Mobile Site | Terms and Conditions | News | Our Company | Contact Us