Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]przeglądarka
Robert007
post 10.10.2009, 09:28:51
Post #1





Grupa: Zarejestrowani
Postów: 167
Pomógł: 2
Dołączył: 1.07.2009
Skąd: Poznań

Ostrzeżenie: (0%)
-----


Witam,

Jak sprawdzić jaką przeglądarkę używa dana osoba przeglądająca stronę ?
Pozdrawiam
Go to the top of the page
+Quote Post
jasin
post 10.10.2009, 09:34:29
Post #2





Grupa: Zarejestrowani
Postów: 142
Pomógł: 32
Dołączył: 21.08.2008
Skąd: Toruń

Ostrzeżenie: (0%)
-----


Tu masz przykłady:

  1. echo '<pre>';
  2. echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
  3.  
  4. $browser = get_browser(null, true);
  5. print_r($browser);

Najlepiej przeglądać wartość $_SERVER['HTTP_USER_AGENT'] . np można napisać jakieś wyrażenie regularne które sprawdza czy wystepują tam ciąg MSIE, Firefox, Chrome ...

Ten post edytował jasin 10.10.2009, 09:39:21


--------------------
Go to the top of the page
+Quote Post
Robert007
post 10.10.2009, 09:39:17
Post #3





Grupa: Zarejestrowani
Postów: 167
Pomógł: 2
Dołączył: 1.07.2009
Skąd: Poznań

Ostrzeżenie: (0%)
-----


Cytat
Warning: get_browser() [function.get-browser]: browscap ini directive not set in


a jak można sprawdzić czy ma aktualnie IE czy FF bo z tego co widziałem na echo to są wszystkie dane a chciałbym jakoś to sprawdzić
Go to the top of the page
+Quote Post
jasin
post 10.10.2009, 09:47:06
Post #4





Grupa: Zarejestrowani
Postów: 142
Pomógł: 32
Dołączył: 21.08.2008
Skąd: Toruń

Ostrzeżenie: (0%)
-----


Nic prostrzego, spr czy występuję interesujący nas ciąg:
  1. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
  2. echo 'Używasz Internet Explorera<br />';
  3. } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) {
  4. echo 'Używasz Firefox<br />';
  5. }


--------------------
Go to the top of the page
+Quote Post
Kshyhoo
post 10.10.2009, 09:57:13
Post #5





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Może tak:
  1. <script language="javascript" type="text/javascript">
  2. <!--
  3. przegladarka = "nieznana";
  4. if (navigator.appName=="Netscape") {
  5. przegladarka = "Netscape lub Mozilla";
  6. } else if (navigator.userAgent.indexOf("Opera")>-1) {
  7. przegladarka = "Opera";
  8. } else if (navigator.appName=="Microsoft Internet Explorer") {
  9. przegladarka = "Internet Explorer";
  10. }
  11. alert("Twoja przeglądarka to: "+przegladarka);
  12. // -->


--------------------
Go to the top of the page
+Quote Post
borat200
post 10.10.2009, 10:05:04
Post #6





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 10.10.2009

Ostrzeżenie: (10%)
X----


Może tak

<?php

function find_browser() {
// Okre�la system operacyjny, jego wersję i typ przeglšdarek użytkowników.
$browser_info = array(
"name" => "Unknown",
"version" => "Unknown",
"OS" => "Unknown",
);
// Uzyskuje agenta użytkownika.
if (!empty($_SERVER["HTTP_USER_AGENT"])) {
$agent = $_SERVER["HTTP_USER_AGENT"];
}

// Znajduje system operacyjny.
if (preg_match('/win/i', $agent)) {
$browser_info["OS"] = "Windows";
} else if (preg_match('/mac/i', $agent)) {
$browser_info["OS"] = "Macintosh";
} else if (preg_match('/linux/i', $agent)) {
$browser_info["OS"] = "Linux";
}

if (preg_match('/opera/i', $agent)) {
// Musimy zaczšć od Opery, ponieważ jej identyfikator pasuje także do łańcucha wła�ciwego przeglšdarce IE.
$browser_info["name"] = "Opera";
$agent = stristr($agent, "Opera");
if (strpos("/", $agent)) {
$agent = explode("/", $agent);
$browser_info["version"] = $agent[1];
} else {
$agent = explode(" ", $agent);
$browser_info["version"] = $agent[1];
}
} else if (preg_match('/msie/i', $agent)) {
$browser_info["name"] = "Internet Explorer";
$agent = stristr($agent,"msie");
$agent = explode(" ", $agent);
$browser_info["version"] = str_replace(";", "", $agent[1]);
} else if (preg_match('/firefox/i', $agent)) {
$browser_info["name"] = "Firefox";
$agent = stristr($agent, "Firefox");
$agent = explode("/", $agent);
$browser_info["version"] = $agent[1];
} else if (preg_match('/safari/i', $agent)) {
$browser_info["name"] = "Safari";
$agent = stristr($agent, "Safari");
$agent = explode("/", $agent);
$browser_info["version"] = $agent[1];
} else if (preg_match('/netscape/i', $agent)) {
$browser_info["name"] = "Netscape Navigator";
$agent = stristr($agent, "Netscape");
$agent = explode("/", $agent);
$browser_info["version"] = $agent[1];
} else if (preg_match('/Gecko/i', $agent)){
$browser_info["name"]= 'Mozilla';
$agent = stristr($agent, "rv");
$agent = explode(":", $agent);
$agent = explode(")", $agent[1]);
$browser_info["version"] = $agent[1];
}
return $browser_info;
}

print_r(find_browser());

?>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 10.06.2024 - 23:08