tag:blogger.com,1999:blog-865923359735383241.post1168104626541176250..comments2023-10-29T07:27:09.012-06:00Comments on Ccna final exam - java, php, javascript, ios, cshap all in one: Mobile Redirect using htaccessUnknownnoreply@blogger.comBlogger5125tag:blogger.com,1999:blog-865923359735383241.post-52956279562565568352012-05-30T03:43:47.002-06:002012-05-30T03:43:47.002-06:00First, go to the following URL and download the mo...First, go to the following URL and download the mobile_detect.php file:<br /><br />http://code.google.com/p/php-mobile-detect/<br /><br />Insert the following code on your index or home page:<br /><br /><?php<br />@include("Mobile_Detect.php");<br />$detect = new Mobile_Detect();<br />if ($detect->isMobile() && isset($_COOKIE['mobile']))<br />{<br />$detect = "false";<br />}<br />elseif ($detect->isMobile())<br />{<br />header("Location:http://www.yourmobiledirectory.com");<br />}<br />?>Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-15099126912050892202012-05-30T03:43:46.380-06:002012-05-30T03:43:46.380-06:00Or you may try this:
?php
/**
* Mobile Detect
* ...Or you may try this:<br /><br />?php<br /><br />/**<br />* Mobile Detect<br />* @license http://www.opensource.org/licenses/mit-license.php The MIT License<br />*/<br />class Mobile_Detect<br />{<br /> protected $accept;<br /> protected $userAgent;<br /> protected $isMobile = false;<br /> protected $isAndroid = null;<br /> protected $isAndroidtablet = null;<br /> protected $isIphone = null;<br /> protected $isIpad = null;<br /> protected $isBlackberry = null;<br /> protected $isBlackberrytablet = null;<br /> protected $isOpera = null;<br /> protected $isPalm = null;<br /> protected $isWindows = null;<br /> protected $isWindowsphone = null;<br /> protected $isGeneric = null;<br /> protected $devices = array(<br /> "android" => "android.*mobile",<br /> "androidtablet" => "android(?!.*mobile)",<br /> "blackberry" => "blackberry",<br /> "blackberrytablet" => "rim tablet os",<br /> "iphone" => "(iphone|ipod)",<br /> "ipad" => "(ipad)",<br /> "palm" => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)",<br /> "windows" => "windows ce; (iemobile|ppc|smartphone)",<br /> "windowsphone" => "windows phone os",<br /> "generic" => "(kindle|mobile|mmp|midp|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap|opera mini)");<br /><br /> public function __construct()<br /> {<br /> $this->userAgent = $_SERVER['HTTP_USER_AGENT'];<br /> $this->accept = $_SERVER['HTTP_ACCEPT'];<br /><br /> if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']))<br /> {<br /> $this->isMobile = true;<br /> }<br /> elseif (strpos($this->accept, 'text/vnd.wap.wml') > 0 || strpos($this->accept, 'application/vnd.wap.xhtml+xml') > 0)<br /> {<br /> $this->isMobile = true;<br /> }<br /> else<br /> {<br /> foreach ($this->devices as $device => $regexp)<br /> {<br /> if ($this->isDevice($device))<br /> {<br /> $this->isMobile = true;<br /> }<br /> }<br /> }<br /> }<br /><br /> /**<br /> * Overloads isAndroid() | isAndroidtablet() | isIphone() | isIpad() | isBlackberry() | isBlackberrytablet() | isPalm() | isWindowsphone() | isWindows() | isGeneric() through isDevice()<br /> *<br /> * @param string $name<br /> * @param array $arguments<br /> * @return bool<br /> */<br /> public function __call($name, $arguments)<br /> {<br /> $device = substr($name, 2);<br /> if ($name == "is" . ucfirst($device) && array_key_exists(strtolower($device), $this->devices))<br /> {<br /> return $this->isDevice($device);<br /> } <br /> else<br /> {<br /> trigger_error("Method $name not defined", E_USER_WARNING);<br /> }<br /> }<br /><br /> /**<br /> * Returns true if any type of mobile device detected, including special ones<br /> * @return bool<br /> */<br /> public function isMobile()<br /> {<br /> return $this->isMobile;<br /> }<br /><br /> protected function isDevice($device)<br /> {<br /> $var = "is" . ucfirst($device);<br /> $return = $this->$var === null ? (bool) preg_match("/" . $this->devices[strtolower($device)] . "/i", $this->userAgent) : $this->$var;<br /> if ($device != 'generic' && $return == true) {<br /> $this->isGeneric = false;<br /> }<br /> return $return;<br />}Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-40440154568255743042012-05-30T03:43:45.620-06:002012-05-30T03:43:45.620-06:00I modified Tim Stone's solution even further. ...I modified Tim Stone's solution even further. This allows the cookie to be in 2 states, 1 for mobile and 0 for full. When the mobile cookie is set to 0 even a mobile browser will go to the full site.<br /><br />Here is the code:<br /><br /><IfModule mod_rewrite.c><br /> RewriteBase /<br /> RewriteEngine On<br /><br /> # Check if mobile=1 is set and set cookie 'mobile' equal to 1<br /> RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)<br /> RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]<br /><br /> # Check if mobile=0 is set and set cookie 'mobile' equal to 0<br /> RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)<br /> RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]<br /><br /> # cookie can't be set and read in the same request so check<br /> RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)<br /> RewriteRule ^ - [S=1]<br /><br /> # Check if this looks like a mobile device<br /> RewriteCond %{HTTP:x-wap-profile} !^$ [OR]<br /> RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]<br /> RewriteCond %{HTTP:Profile} !^$<br /><br /> # Check if we're not already on the mobile site<br /> RewriteCond %{HTTP_HOST} !^m\.<br /> # Check to make sure we haven't set the cookie before<br /> RewriteCond %{HTTP:Cookie} !\mobile=0(;|$)<br /> # Now redirect to the mobile site<br /> RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]<br /></IfModule>Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-84489349377059040802012-05-30T03:43:44.536-06:002012-05-30T03:43:44.536-06:00Tim Stone's solution is on the right track, bu...Tim Stone's solution is on the right track, but his initial rewriterule and and his cookie name in the final condition are different, and you can not write and read a cookie in the same request.<br /><br />Here is the finalized working code:<br /><br />RewriteEngine on<br />RewriteBase /<br /># Check if this is the noredirect query string<br />RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)<br /># Set a cookie, and skip the next rule<br />RewriteRule ^ - [CO=mredir:0:www.website.com]<br /><br /># Check if this looks like a mobile device<br /># (You could add another [OR] to the second one and add in what you<br /># had to check, but I believe most mobile devices should send at<br /># least one of these headers)<br />RewriteCond %{HTTP:x-wap-profile} !^$ [OR]<br />RewriteCond %{HTTP:Profile} !^$ [OR]<br />RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]<br />RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]<br />RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]<br /><br /># Check if we're not already on the mobile site<br />RewriteCond %{HTTP_HOST} !^m\.<br /># Can not read and write cookie in same request, must duplicate condition<br />RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) <br /><br /># Check to make sure we haven't set the cookie before<br />RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]<br /><br /># Now redirect to the mobile site<br />RewriteRule ^ http://m.website.com [R,L]Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-49998005770295755102012-05-30T03:43:43.499-06:002012-05-30T03:43:43.499-06:00I tested bits and pieces of the following, but not...I tested bits and pieces of the following, but not the complete rule set in its entirety, so if you run into trouble with it let me know and I'll dig around a bit more. However, assuming I got everything correct, you could try something like the following:<br /><br />RewriteEngine On<br /><br /># Check if this is the noredirect query string<br />RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)<br /># Set a cookie, and skip the next rule<br />RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]<br /><br /># Check if this looks like a mobile device<br /># (You could add another [OR] to the second one and add in what you<br /># had to check, but I believe most mobile devices should send at<br /># least one of these headers)<br />RewriteCond %{HTTP:x-wap-profile} !^$ [OR]<br />RewriteCond %{HTTP:Profile} !^$<br /># Check if we're not already on the mobile site<br />RewriteCond %{HTTP_HOST} !^m\.<br /># Check to make sure we haven't set the cookie before<br />RewriteCond %{HTTP:Cookie} !\smredir=0(;|$)<br /># Now redirect to the mobile site<br />RewriteRule ^ http://m.example.org%{REQUEST_URI} [R,L]Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.com