Welcome!

And don't forget to edit your signature & profile.

 

Icon

Statistics

  • Total posts 23326
  • Total topics 4050
  • Total members 5576
  • Our newest member
    feha

TOP POSTERS

Detect mobile Device is creating Loop - Please help

All problems and developments related to PHP, Ruby on Rails & Co. are discussed and resolved here.
   
Hello People

i am creating a Switch to detect mobile Devices and route them internal in my CMS.
But the Script is creating a never ending Loop.
With a Session i am handling the case "mobile" or "desktop".

The Script is loaded on every Page in the Header, because i have a basic Template and above it is the Script.

Do you see the Error? I might be work blind.
Thanks ;)

Code: Select all
<?php
   session_start();
   if(!isset($_SESSION['client'][0]))
   {
   // Detects if browser is mobile or not
   $mobile_browser = '0';
   
   if(preg_match('/(up.browser|up.link|windows   ce|iemobile|mmp|symbian|smartphone|midp|wap|phone|vodafone|o2|pocket|mobile|pda|psp)/i',strtolower($_SERVER['HTTP_USER_AGENT']))){
      $mobile_browser++;
   }

   if(((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'text/vnd.wap.wml')>0) or (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0)) or ((((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or isset($_SERVER['X-OperaMini-Features']) or isset($_SERVER['UA-pixels'])))))){
   $mobile_browser++;
}

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents = array('acs-','alav','alca','amoi','audi','aste','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','opwv','palm','pana','pant','pdxg','phil','play','pluc','port','prox','qtek','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-');


   if(in_array($mobile_ua,$mobile_agents)){
      $mobile_browser++;
   }

   if($mobile_browser>0){
         $_SESSION['client'] = array('mobile');
      }else{
         $_SESSION['client'] = array('desktop');
   }

   }
   // End of !isset()
   
   
   // The Session is set: Go and switch the header.
   if(isset($_SESSION['client'][0])){
      switch($_SESSION['client'][0])
      {
         case "mobile":
            header('Location: '.rex_getUrl(2)); # Go to mobile Page // rex_getUrl() is a Command for the CMS I use
         break;
         case "desktop":
            header('Location: '.rex_getUrl(1)); # Go to regular Page // rex_getUrl() is a Command for the CMS I use
         break;
      }
   }
?>


How can i tell the script, go to the switch Case once and then use "mobile" or "desktop" as default?
"A day without a Table is a good day."
User avatar
breastfed
Smashing <table>
 
Posts: 46
Joined: Tue Apr 07, 2009 1:17 pm
Location: Dülmen, Germany
   

Return to Server-side Scripting



Who is online

Users browsing this forum: MSN [Bot] and 1 guest