Centar za edukaciju-BiH



#1 19.10.2021 15:38
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Postovi:4,807


Predmet:Detekcija browsera
Kako da ovaj kod dole prepozna vivaldija

PreuzmiIzvorni kôd (Javascript):
  1. <HTML>
  2.     <HEAD>
  3.     <TITLE>PROBA JAVASCRIPT KODA</TITLE>
  4.      
  5.     <script>
  6.     <!-- funkcija -->
  7.      
  8.     //gets the type of browser
  9.     function detectBrowser() {
  10.         if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) {
  11.             return 'Opera';
  12.         } else if(navigator.userAgent.indexOf("Chrome") != -1 ) {
  13.             return 'Chrome';
  14.         } else if(navigator.userAgent.indexOf("Safari") != -1) {
  15.             return 'Safari';
  16.         } else if(navigator.userAgent.indexOf("Firefox") != -1 ){
  17.             return 'Firefox';
  18.         } else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) {
  19.             return 'IE';//crap
  20.         } else {
  21.             return 'Unknown';
  22.         }
  23.     }
  24.      
  25.     </script>
  26.     </HEAD>
  27.     <BODY>
  28.     <script>
  29.     <!--pozivanje funkcije-->
  30.      
  31.     var nVer = navigator.appVersion;
  32.     var nAgt = navigator.userAgent;
  33.     var browserName  = navigator.appName;
  34.     var fullVersion  = ''+parseFloat(navigator.appVersion);
  35.     var majorVersion = parseInt(navigator.appVersion,10);
  36.     var nameOffset,verOffset,ix;
  37.      
  38.     // In Opera 15+, the true version is after "OPR/"
  39.     if ((verOffset=nAgt.indexOf("OPR/"))!=-1) {
  40.      browserName = "Opera";
  41.      fullVersion = nAgt.substring(verOffset+4);
  42.     }
  43.     // In older Opera, the true version is after "Opera" or after "Version"
  44.     else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
  45.      browserName = "Opera";
  46.      fullVersion = nAgt.substring(verOffset+6);
  47.      if ((verOffset=nAgt.indexOf("Version"))!=-1)
  48.        fullVersion = nAgt.substring(verOffset+8);
  49.     }
  50.     // In MSIE, the true version is after "MSIE" in userAgent
  51.     else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
  52.      browserName = "Microsoft Internet Explorer";
  53.      fullVersion = nAgt.substring(verOffset+5);
  54.     }
  55.     // In Chrome, the true version is after "Chrome"
  56.     else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
  57.      browserName = "Chrome";
  58.      fullVersion = nAgt.substring(verOffset+7);
  59.     }
  60.     // In Safari, the true version is after "Safari" or after "Version"
  61.     else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
  62.      browserName = "Safari";
  63.      fullVersion = nAgt.substring(verOffset+7);
  64.      if ((verOffset=nAgt.indexOf("Version"))!=-1)
  65.        fullVersion = nAgt.substring(verOffset+8);
  66.     }
  67.     // In Firefox, the true version is after "Firefox"
  68.     else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
  69.      browserName = "Firefox";
  70.      fullVersion = nAgt.substring(verOffset+8);
  71.     }
  72.     // In most other browsers, "name/version" is at the end of userAgent
  73.     else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) <
  74.               (verOffset=nAgt.lastIndexOf('/')) )
  75.     {
  76.      browserName = nAgt.substring(nameOffset,verOffset);
  77.      fullVersion = nAgt.substring(verOffset+1);
  78.      if (browserName.toLowerCase()==browserName.toUpperCase()) {
  79.       browserName = navigator.appName;
  80.      }
  81.     }
  82.     // trim the fullVersion string at semicolon/space if present
  83.     if ((ix=fullVersion.indexOf(";"))!=-1)
  84.        fullVersion=fullVersion.substring(0,ix);
  85.     if ((ix=fullVersion.indexOf(" "))!=-1)
  86.        fullVersion=fullVersion.substring(0,ix);
  87.      
  88.     majorVersion = parseInt(''+fullVersion,10);
  89.     if (isNaN(majorVersion)) {
  90.      fullVersion  = ''+parseFloat(navigator.appVersion);
  91.      majorVersion = parseInt(navigator.appVersion,10);
  92.     }
  93.      
  94.     document.write(''
  95.      +'Browser name  = '+browserName+'<br>'
  96.      +'Full version  = '+fullVersion+'<br>'
  97.      +'Major version = '+majorVersion+'<br>'
  98.      +'navigator.appName = '+navigator.appName+'<br>'
  99.      +'navigator.userAgent = '+navigator.userAgent+'<br>'
  100.     )
  101.      
  102.     </script>
  103.     </BODY>
  104.     </HTML>

zivot je moja domovina.
↑  ↓

#2 20.10.2021 14:26
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,642


Predmet:Re:Detekcija browsera
Zasad pokazuju isto sve chrome i vivaldi pa neznas koji je koji.
Sa php bi se mozda i moglo.
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

#3 20.10.2021 14:45
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Postovi:4,807


Predmet:Re:Detekcija browsera
Nesto mi ovo nece, a neznam sta je . Nesto prije join

PreuzmiIzvorni kôd (PHP):
  1. <HTML>
  2. <HEAD>
  3. <TITLE>PHP DETEKCIJA BROWSERA</TITLE>
  4.  
  5.  
  6. </HEAD>
  7. <BODY>
  8.  
  9. <?php
  10. function getBrowser() {
  11.   $u_agent = $_SERVER['HTTP_USER_AGENT'];
  12.   $bname = 'Unknown';
  13.   $platform = 'Unknown';
  14.   $version= "";
  15.  
  16.   //First get the platform?
  17.   if (preg_match('/linux/i', $u_agent)) {
  18.     $platform = 'linux';
  19.   }elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
  20.     $platform = 'mac';
  21.   }elseif (preg_match('/windows|win32/i', $u_agent)) {
  22.     $platform = 'windows';
  23.   }
  24.  
  25.   // Next get the name of the useragent yes seperately and for good reason
  26.   if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)){
  27.     $bname = 'Internet Explorer';
  28.     $ub = "MSIE";
  29.   }elseif(preg_match('/Firefox/i',$u_agent)){
  30.     $bname = 'Mozilla Firefox';
  31.     $ub = "Firefox";
  32.   }elseif(preg_match('/OPR/i',$u_agent)){
  33.     $bname = 'Opera';
  34.     $ub = "Opera";
  35.   }elseif(preg_match('/Chrome/i',$u_agent) && !preg_match('/Edge/i',$u_agent)){
  36.     $bname = 'Google Chrome';
  37.     $ub = "Chrome";
  38.   }elseif(preg_match('/Safari/i',$u_agent) && !preg_match('/Edge/i',$u_agent)){
  39.     $bname = 'Apple Safari';
  40.     $ub = "Safari";
  41.   }elseif(preg_match('/Netscape/i',$u_agent)){
  42.     $bname = 'Netscape';
  43.     $ub = "Netscape";
  44.   }elseif(preg_match('/Edge/i',$u_agent)){
  45.     $bname = 'Edge';
  46.     $ub = "Edge";
  47.   }elseif(preg_match('/Trident/i',$u_agent)){
  48.     $bname = 'Internet Explorer';
  49.     $ub = "MSIE";
  50.   }
  51.  
  52.   // finally get the correct version number
  53.   $known = array('Version', $ub, 'other');
  54.   $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
  55.   if (!preg_match_all($pattern, $u_agent, $matches)) {
  56.     // we have no matching number just continue
  57.   }
  58.   // see how many we have
  59.   $i = count($matches['browser']);
  60.   if ($i != 1) {
  61.     //we will have two since we are not using 'other' argument yet
  62.     //see if version is before or after the name
  63.     if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
  64.         $version= $matches['version'][0];
  65.     }else {
  66.         $version= $matches['version'][1];
  67.     }
  68.   }else {
  69.     $version= $matches['version'][0];
  70.   }
  71.  
  72.   // check if we have a number
  73.   if ($version==null || $version=="") {$version="?";}
  74.  
  75.   return array(
  76.     'userAgent' => $u_agent,
  77.     'name'      => $bname,
  78.     'version'   => $version,
  79.     'platform'  => $platform,
  80.     'pattern'    => $pattern
  81.   );
  82. }
  83.  
  84. // now try it
  85. $ua=getBrowser();
  86. $yourbrowser= "Your browser: " . $ua['name'] . " " . $ua['version'] . " on " .$ua['platform'] . " reports: <br >" . $ua['userAgent'];
  87. print_r($yourbrowser);
  88. ?>
  89.  
  90. </BODY>
  91. </HTML>

zivot je moja domovina.
↑  ↓

#4 22.10.2021 00:49
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,642


Predmet:Re:Detekcija browsera
kod mene radi.
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

#5 22.10.2021 11:54
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Postovi:4,807


Predmet:Re:Detekcija browsera
evo sta pokaze kod mene


zivot je moja domovina.
↑  ↓

#6 26.10.2021 15:38
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,642


Predmet:Re:Detekcija browsera
Pa moras imati php interpeter ili mozda lakse reci kompajler.
Mora biti na serveru da bi radio php kod.
javascript nemora.
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

#7 27.10.2021 12:14
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Postovi:4,807


Predmet:Re:Detekcija browsera
pa ako napravim jednostavnu stranicu u html
i onda pokrenem UwAmp
tu stranicu vidim a ovu gore ne
sto radim krivo?
zivot je moja domovina.
↑  ↓

#8 27.10.2021 18:23
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,642


Predmet:Re:Detekcija browsera
za html netreba server.
ali za php treba.
znaci ako imas php koda onda mora stranica biti php:
priimjer :
neka se zove index.php.
Njen sadrzaj:
<?php
ovdje kucas php kod
?>
iza ovog mozes pisati html napr;
<HTML>
<HEAD>
<TITLE>PHP DETEKCIJA BROWSERA</TITLE>


</HEAD>
<BODY>
iza body je html.
Moglo je ovo biti i prije php.
ako ne uspijes onda idemo detaljno jedno po jedno.
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

#9 28.10.2021 09:19
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Postovi:4,807


Predmet:Re:Detekcija browsera
local server: UwAmp
ime datoteke: index.html
kod:
PreuzmiIzvorni kôd (HTML):
  1.     <HTML>
  2.     <HEAD>
  3.     <TITLE>PHP DETEKCIJA BROWSERA</TITLE>
  4.      
  5.      
  6.     </HEAD>
  7.     <BODY>
  8.      
  9.     <?php
  10.    function getBrowser() {
  11.      $u_agent = $_SERVER['HTTP_USER_AGENT'];
  12.      $bname = 'Unknown';
  13.      $platform = 'Unknown';
  14.      $version= "";
  15.    
  16.      //First get the platform?
  17.      if (preg_match('/linux/i', $u_agent)) {
  18.        $platform = 'linux';
  19.      }elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
  20.        $platform = 'mac';
  21.      }elseif (preg_match('/windows|win32/i', $u_agent)) {
  22.        $platform = 'windows';
  23.      }
  24.    
  25.      // Next get the name of the useragent yes seperately and for good reason
  26.      if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)){
  27.        $bname = 'Internet Explorer';
  28.        $ub = "MSIE";
  29.      }elseif(preg_match('/Firefox/i',$u_agent)){
  30.        $bname = 'Mozilla Firefox';
  31.        $ub = "Firefox";
  32.      }elseif(preg_match('/OPR/i',$u_agent)){
  33.        $bname = 'Opera';
  34.        $ub = "Opera";
  35.      }elseif(preg_match('/Chrome/i',$u_agent) && !preg_match('/Edge/i',$u_agent)){
  36.        $bname = 'Google Chrome';
  37.        $ub = "Chrome";
  38.      }elseif(preg_match('/Safari/i',$u_agent) && !preg_match('/Edge/i',$u_agent)){
  39.        $bname = 'Apple Safari';
  40.        $ub = "Safari";
  41.      }elseif(preg_match('/Netscape/i',$u_agent)){
  42.        $bname = 'Netscape';
  43.        $ub = "Netscape";
  44.      }elseif(preg_match('/Edge/i',$u_agent)){
  45.        $bname = 'Edge';
  46.        $ub = "Edge";
  47.      }elseif(preg_match('/Trident/i',$u_agent)){
  48.        $bname = 'Internet Explorer';
  49.        $ub = "MSIE";
  50.      }
  51.    
  52.      // finally get the correct version number
  53.      $known = array('Version', $ub, 'other');
  54.      $pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
  55.       if (!preg_match_all($pattern, $u_agent, $matches)) {
  56.         // we have no matching number just continue
  57.       }
  58.       // see how many we have
  59.       $i = count($matches['browser']);
  60.       if ($i != 1) {
  61.         //we will have two since we are not using 'other' argument yet
  62.         //see if version is before or after the name
  63.         if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
  64.            $version= $matches['version'][0];
  65.        }else {
  66.            $version= $matches['version'][1];
  67.        }
  68.      }else {
  69.        $version= $matches['version'][0];
  70.      }
  71.    
  72.      // check if we have a number
  73.      if ($version==null || $version=="") {$version="?";}
  74.    
  75.      return array(
  76.        'userAgent' => $u_agent,
  77.         'name'      => $bname,
  78.         'version'   => $version,
  79.         'platform'  => $platform,
  80.         'pattern'    => $pattern
  81.       );
  82.     }
  83.      
  84.     // now try it
  85.     $ua=getBrowser();
  86.     $yourbrowser= "Your browser: " . $ua['name'] . " " . $ua['version'] . " on " .$ua['platform'] . " reports: <br >" . $ua['userAgent'];
  87.     print_r($yourbrowser);
  88.     ?>
  89.      
  90.     </BODY>
  91.     </HTML>

my-app
ime foldera: detekcija browsera

rezultat:
' . join('|', $known) . ')[/ ]+(?[0-9.|a-zA-Z.]*)#'; if (!preg_match_all($pattern, $u_agent, $matches)) { // we have no matching number just continue } // see how many we have $i = count($matches['browser']); if ($i != 1) { //we will have two since we are not using 'other' argument yet //see if version is before or after the name if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){ $version= $matches['version'][0]; }else { $version= $matches['version'][1]; } }else { $version= $matches['version'][0]; } // check if we have a number if ($version==null || $version=="") {$version="?";} return array( 'userAgent' => $u_agent, 'name' => $bname, 'version' => $version, 'platform' => $platform, 'pattern' => $pattern ); } // now try it $ua=getBrowser(); $yourbrowser= "Your browser: " . $ua['name'] . " " . $ua['version'] . " on " .$ua['platform'] . " reports:
" . $ua['userAgent']; print_r($yourbrowser); ?>
zivot je moja domovina.
Ovaj post je ureden 1 puta. Posljednja izmjena 28.10.2021 09:19 od strane Avko. ↑  ↓

#10 28.10.2021 19:00
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,642


Predmet:Re:Detekcija browsera
e pa nemoze ti u htm biti php jer se html izvrsava na klijentu.
preimenuj datoteku u php.
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

Stranice (2):1,2


Sva vremena su GMT +01:00. Trenutno vrijeme: 1: 38 am.