Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
browser detect

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 14.10.2006 23:11    Post subject: browser detect Add user to your forum ignore list Reply with quote

ova funkcija mi za operu vraca "OTHER", za IE radi. btw, nisam je ja napisala.
Code:
<?php
$detect = detect();
$browser = $detect['browser'];
$version = $detect['version'];
$os = $detect['os'];
function detect()
   {
   $browser = array ("IE","OPERA","MOZILLA","NETSCAPE","FIREFOX","SAFARI");
   $os = array ("WIN","MAC");
   $info['browser'] = "OTHER";
   $info['os'] = "OTHER";
   foreach ($browser as $parent)
      {
      $s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent);
      $f = $s + strlen($parent);
      $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
      $version = preg_replace('/[^0-9,.]/','',$version);
      if ($s)
         {
         $info['browser'] = $parent;
         $info['version'] = $version;
         }
      }
   foreach ($os as $val)
      {
      if (eregi($val,strtoupper($_SERVER['HTTP_USER_AGENT']))) $info['os'] = $val;
      }
   return $info;
   }
?>

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
sinke



Joined: 02 Oct 2005
Posts: 257
Location: Zagreb

PostPosted: 14.10.2006 23:57    Post subject: Add user to your forum ignore list Reply with quote

U Operi se može mjenjati user agent, a koliko se sjećam u starijim verzijama je IE simulacija bila default (neznam kako je u novijim)... Pročitaj malo komentare na taj kod, tamo gdje si ga i uzela. Ima i link na stari maratzov post.

_________________
THE SHTANZIG | Web Do's & Don'ts
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 15.10.2006 00:10    Post subject: Add user to your forum ignore list Reply with quote

Fakat loša browser detect skripta Confused

evo moja (dio klase), izvuci što ti treba:
  • kuži dosta spidera i botova;
  • hvata version string - kuži (donekle) čudne Safari verzije;
  • ne hvata kao IE browsere koji se predstavljaju kao IE (npr. Opera).


Code:
static function parse_user_agent($ua = NULL){
      if(!$ua && !($ua = @$_SERVER['HTTP_USER_AGENT'])) return false;
      $browser['minorver'] = $browser['majorver'] = $browser['platform'] = $browser['version'] = $browser['browser'] = NULL;
      
      // Test for platform
      if(eregi('Win',$ua)) $browser['platform'] = 'Windows';
      else if(eregi('Mac',$ua)) $browser['platform'] = 'Macintosh';
      else if(eregi('Linux',$ua)) $browser['platform'] = 'Linux';
      else if(eregi('Amiga',$ua)) $browser['platform'] = 'AmigaOS';
      
      // Test for browser type
      if(preg_match('%Mozilla[ /](4(\.0)?)%', $ua, $matches) && !eregi('compatible',$ua)){
         $browser['browser'] = 'Netscape';
         $browser['version'] = $matches[1];
         }
      if(preg_match('%(Mozilla/5|Gecko)%',$ua)){
         $browser['browser'] = 'Mozilla';
         eregi('rv(:| )([[:digit:]\.]+)',$ua,$b);
         $browser['version'] = $b[2];
         }
      /* spiders, crawlers & other automatons */
      if(preg_match('%
         spider | crawl | bot | walker | archiver | mediapartners-google | indexer | fetch | URL[_ ]control | detectURL
         # GoogleBot (www.googlebot.com/bot.html)
         | W3C_(CSS_)?Validator
         | Slurp # Yahoo! (help.yahoo.com/help/us/ysearch/slurp)
         | Teoma # Ask Jeeves (http://sp.ask.com/docs/about/tech_crawling.html)
         | grub-client #www.grub.org (interesting!)
         | pogodak.hr #www.pogodak.hr
         | Wget #www.gnu.org/software/wget/wget.html
         | Xenu\ Link\ Sleuth #http://home.snafu.de/tilman/xenulink.html
         | Trend\ Micro #www.trendmicro.com
         | sohu-search #http://dir.sogou.com (good luck)
         | appie #www.walhello.com
         | \bNG/[1-9] #http://beta.exalead.com/search
         | Offline\ Commander
         | ccubee #ccubee.com
         | Robozilla #http://dmoz.org/profiles/robozilla.html
         | ActiveBookmark
         | Scooter #AltaVista
         | Infoseek
         | Lycos
         | Gulliver
         | Zlatno #http://zlatno.com
         | CacheabilityEngine #http://www.mnot.net/cacheability/
         | WWW.HR\ getmeta_agent
         | PHP\ version\ tracker
         | trazilica
         | HTTrack
         | Pompos #dir.com/pompos.html
         | SearchGuild #searchguild.com
         | ShowTags
         | ichiro
         # libwww-perl #http://lwp.linpro.no/lwp/ (what to do with THIS?)
         %ix',$ua)){
         $browser['browser'] = 'Crawler/Search Engine';
         // return immediately because crawlers are pretty dull
         return $browser;
         }
      /* match most of the browsers nowadays */
      if(preg_match('%
         (
            Fire(?:fox|bird)
            | Phoenix
            | iCab
            | Camino
            | Chimera
            | Netscape[0-9]?
            | OmniWeb
            | Lynx
            | Konqueror
            | Opera
            | Safari
            | Links
            | MIB
            | libcurl
            | amaya
            | Voyager
            | UP.Browser
            | Silk
         )
            [ /(] ([\d.]+) %ix', $ua, $matches)){
         $browser['browser'] = $matches[1];
         $browser['version'] = $matches[2];
         
         /* fix individual matches */
         switch($browser['browser']){
            case 'Safari':
               $browser['platform'] = 'Macintosh';
               if($browser['version']<85) $browser['version']    = 'Pre-1.0 Beta';
               else {
                  preg_match('%^(\d+)(?:\.(\d+)(?:\.(\d+))?)?%', $browser['version'], $matches);
                  switch($matches[1]){
                     case 85:
                        $browser['majorver'] = 1;
                        $browser['minorver'] = 0;
                        break;
                     case 125:
                        $browser['majorver'] = 1;
                        $browser['minorver'] = 2;
                        break;
                     case 312:
                        $browser['majorver'] = 1;
                        $browser['minorver'] = 3;
                        break;
                     case 412:
                        $browser['majorver'] = 2;
                        $browser['minorver'] = 0;
                        break;
                  }
                  $browser['version'] = $browser['majorver'].'.'.$browser['minorver'];
                  }
               break;
            case 'MIB':
               $browser['browser'] = 'Motorolla Internet Browser';
               break;
            case 'Netscape6':
               $browser['browser'] = 'Netscape';
               $browser['version'] = 6;
               break;
            case 'libcurl':
               $browser['browser'] = 'cURL';
               break;
            }
         }
      else if(eregi('Voyager',$ua) && eregi('Amiga',$ua)){
         $browser['browser'] = 'Voyager';
         }
      // if not any of the above, it must be IE
      else if(preg_match('%MSIE ([\d.]+)%',$ua,$matches)){
         $browser['browser'] = 'Internet Explorer';
         $browser['version'] = $matches[1];
         }
      
      // Determine browser versions
      if($browser['browser']!='Safari' && !is_null($browser['browser']) && $browser['browser'] != 'Crawler/Search Engine' && !is_null($browser['version'])) {
         // Make sure we have at least .0 for a minor version
         $browser['version'] = (!eregi('\.',$browser['version'])) ? $browser['version'].'.0' : $browser['version'];
         
         eregi('^([0-9]*).(.*)$',$browser['version'],$v);
         $browser['majorver'] = $v[1];
         $browser['minorver'] = $v[2];
         }
      if(empty($browser['version']) || $browser['version']=='.0') {
         $browser['version'] = $browser['majorver'] = $browser['minorver'] = NULL;
         }
      
      return $browser;
      }
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mile



Joined: 10 Sep 2003
Posts: 1327
Location: Jeruzalem

PostPosted: 15.10.2006 00:31    Post subject: Add user to your forum ignore list Reply with quote

to je korisno ako želiš negdje na stranici prikazati upozorenje: 'You should stop using Internet Explorer' Smile

_________________
mile.is
Back to top
View user's profile Send private message Visit poster's website
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 15.10.2006 12:52    Post subject: Add user to your forum ignore list Reply with quote

tnx, Sulien.. pokusati cu.
btw zasto ne lovi i kad se Opera predstavlja kao IE? svejedno mi je je li Opera ili IE.

@mile: ne bas, pokusavam dobiti funkcionalnost :target pomocu JavaScript-a, posto samo Mozilla podrzava CSS

Last edited by nel`chee on 15.10.2006 14:12; edited 2 times in total

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 15.10.2006 13:58    Post subject: Add user to your forum ignore list Reply with quote

mile: ja to radim sa ovom funkcijom, za IE < 6
Code:
   protected function _oldUserAgent(){
      if($ua = @$_SERVER['HTTP_USER_AGENT']){
         if(preg_match('/MSIE (\d)\.(\d+); Windows/', $ua, $matches) &&
            strpos($ua, 'Opera') === false &&
            $matches[1] < 6){
            return sprintf('Internet Explorer %d.%d', $matches[1], $matches[2]);
         }
      }
      return false;
   }

prikažem strašni žuto-crveni box u kojem piše poruka da moraju upgrade-ati browser i linkove na Firefox i Operu, ali ne i link na IE update, hehe Twisted Evil

nelchee: iz cijele user-agent detekcije naravno uzmeš samo što ti treba, ostalo izbaciš zbog brzine... i ako pokušavaš dobiti :target JavaScriptom, što će ti server-side detekcija?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 15.10.2006 14:14    Post subject: Add user to your forum ignore list Reply with quote

iskreno.. nemam pojma. totalni sam idiot za javascript (a za php kao nesto manji)... pa sam mislila da ce tako biti bolje.

problem je sto Opera ne kuzi ovaj JavaScript koji sam pokupila s HTML Dog Mad
sftarget.js - malo modificiran jer navodno samo IE/win kuzi window.attachEvent, ali svejedno ne radi.

one of these days trebala bi poceti uciti JS, znam, samo nemam kad... Confused

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
maratz
mi3.crew


Joined: 24 Nov 2003
Posts: 1207
Location: ZAG

PostPosted: 15.10.2006 15:43    Post subject: Add user to your forum ignore list Reply with quote

u JavaScriptu se Opera pouzdano detektira testiranjem window objekta 'opera':
Code:
var browser_is_opera = window.opera ? true : false;

više ovdje: http://www.opera.com/support/tutorials/userjs/

_________________
STOP HITTING YOURSELF! | NETIQUETTE | TYPETESTER | Hypertext rulez™ | CREATIVE NIGHTS | ACCOMMODATIONS
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 15.10.2006 16:06    Post subject: Add user to your forum ignore list Reply with quote

koji je točno problem vezan uz :target koji u Operi treba zaobići? Nju zahvati hack namijenjen IE-u -- ili nešto drugo?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 16.10.2006 19:38    Post subject: Add user to your forum ignore list Reply with quote

@maratz: tnx! doduse, detekcija sama za sebe mi nece pomoci - trebam nekako pozvati ovu funkciju, a posto ne razumijem JS uopce, ne znam kako da modificiram ovu skriptu da proradi u Operi.

@Sulien: problem je u tome sto ona ne reagira na CSS :target. ocekivala sam da bi trebala, ali ne mrda kao ni IE, a sudeci prema komentarima na HTML Dog i oni znaju da doticni CSS + JS ne rade u Operi i nije im bed zbog toga.

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group