Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]przeglądarka
Robert007
post
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
 
Start new topic
Odpowiedzi
borat200
post
Post #2





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

Posty w temacie


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

 



RSS Aktualny czas: 14.10.2025 - 14:25