I have put together a mobile website for us, and have the main site, madisonstudios.com, redirecting to the mobile site, madisonstudios.mobi, if the device is a mobile device.
I also put a full website button on the mobile site, and when the referrer is the mobile site, it sets a cookie, but I had a problem with still having it redirecting on the first click to the full site, and then once you clicked it the second time it went to the full website.
To solve this issue I added a variable of $setcookie and set it to 1, so to make it skip the redirect. My code below.
I think this is a kind of messy way to do this, and think that there has to be a cleaner way, does anyone have a suggestion that would make sense for me to use. Am I going about this the right way?
<?php
if($_SERVER['HTTP_REFERER'] == "http://www.madisonstudios.mobi/" || $_SERVER['HTTP_REFERER'] == "http://madisonstudios.mobi/")
{
setcookie('fromMobi', true, time()+3600*24);
$setcookie = 1;
}
if ($_COOKIE["fromMobi"] == 1 || $setcookie == 1)
{
} else {
$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","webos");
foreach($uamatches as $uastring){
if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"]))
{
header('Location: http://www.madisonstudios.mobi');
}
}
}
?>
I would do this: