Показване на версията на браузер

talevtehnology

Registered
Здравейте с този javascript разбирам кой с какъв браузър е но въпроса ми е как мога с пхп да показвам определена част от информацията като например какъв е браузера и коя му е версията :)
Код:
<html>
<body>

<script type="text/javascript">
document.write("Browser CodeName: " + navigator.appCodeName);
document.write("<br /><br />");
document.write("Browser Name: " + navigator.appName);
document.write("<br /><br />");
document.write("Browser Version: " + navigator.appVersion);
document.write("<br /><br />");
document.write("Cookies Enabled: " + navigator.cookieEnabled);
document.write("<br /><br />");
document.write("Platform: " + navigator.platform);
document.write("<br /><br />");
document.write("User-agent header: " + navigator.userAgent);
</script>

</body>
</html>

Иначе javascripta изважда това:

Browser CodeName: Mozilla

Browser Name: Netscape

Browser Version: 5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4

Cookies Enabled: true

Platform: Linux i686

User-agent header: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4
 
Така ?

Код:
<?php
$os = getos();
$agent2 = $_SERVER['HTTP_USER_AGENT'];
function getos(){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($agent,'Win')){
if(strstr($agent,'NT 5.0') || strstr($agent,'NT5.0') || strstr($agent,'Windows 2000')){ $os = "Windows 2000";
}else if(strstr($agent,'NT 5.1') || strstr($agent,'NT5.1') || strstr($agent,'Windows XP')){$os = "Windows XP";
}else if(strstr($agent,'Win98') || strstr($agent,'Windows 98')){$os="Windows 98";
}else if(strstr($agent,'NT')) {$os='Windows NT';
}else if(strstr($agent,'Win95') || strstr($agent,'Windows 95')){$os='Windows 95';
}else if(strstr($agent,'Win 9x')) {$os='Windows 95';
}else if(strstr($agent,'WinME') || strstr($agent,'Windows ME')){$os='Windows ME';
}else{$os='Windows (version unspecified)';}

}else if (strstr($agent,'Mac')){$os='Apple Macintosh';
}else if (strstr($agent,'Linux')){$os='Linux';
}else if (strstr($agent,'BeOS')){$os='BeOS';
}else if (strstr($agent,'Unix') || strstr($agent, "HP-ux") || strstr($agent, "X11")){$os='Unix';
}else if (strstr($agent,'SunOS')){$os='SunOS';
}else if (strstr($agent,'FreeBSD')){$os='FreeBSD';
}else if (strstr($agent,'OpenBSD')){$os='OpenBSD';
}else if (strstr($agent,'IRIX')){$os='IRIX';
}else if (strstr($agent,'spider') || strstr($agent,'bot') || strstr($agent,'http') || strstr($agent,'Scooter') || strstr($agent,'WebCopier')){$os='Spiders';
}else{$os='Unspecified';
}
return $os;
}

echo "
<html>
<head>
<title>test..</title>
</head>
<body>
<br>
<h2 align='center'>IP Information</h2>
<center>

Browser Name: $agent<br/>
Browser Version: $agent2<br />

Cookies Enabled: 		<script Language=\"JavaScript\">
		
		</script>
<br/>
Platform: $os";
?>

Между другото сега потърсих в Интернет, виж и тези линкове може да ти помогнат:

php browser detection

get browser

Първия линк е скрипт мисля, защото можеше и да се свали.
 
Код:
$agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match("#Firefox\/(.+)#", $agent, $m)) {
	echo "Browser: Mozilla Firefox v.".$m[1];
}
Да речем.
 
nom3r1 каза:
Така ?

Код:
<?php
$os = getos();
$agent2 = $_SERVER['HTTP_USER_AGENT'];
function getos(){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($agent,'Win')){
if(strstr($agent,'NT 5.0') || strstr($agent,'NT5.0') || strstr($agent,'Windows 2000')){ $os = "Windows 2000";
}else if(strstr($agent,'NT 5.1') || strstr($agent,'NT5.1') || strstr($agent,'Windows XP')){$os = "Windows XP";
}else if(strstr($agent,'Win98') || strstr($agent,'Windows 98')){$os="Windows 98";
}else if(strstr($agent,'NT')) {$os='Windows NT';
}else if(strstr($agent,'Win95') || strstr($agent,'Windows 95')){$os='Windows 95';
}else if(strstr($agent,'Win 9x')) {$os='Windows 95';
}else if(strstr($agent,'WinME') || strstr($agent,'Windows ME')){$os='Windows ME';
}else{$os='Windows (version unspecified)';}

}else if (strstr($agent,'Mac')){$os='Apple Macintosh';
}else if (strstr($agent,'Linux')){$os='Linux';
}else if (strstr($agent,'BeOS')){$os='BeOS';
}else if (strstr($agent,'Unix') || strstr($agent, "HP-ux") || strstr($agent, "X11")){$os='Unix';
}else if (strstr($agent,'SunOS')){$os='SunOS';
}else if (strstr($agent,'FreeBSD')){$os='FreeBSD';
}else if (strstr($agent,'OpenBSD')){$os='OpenBSD';
}else if (strstr($agent,'IRIX')){$os='IRIX';
}else if (strstr($agent,'spider') || strstr($agent,'bot') || strstr($agent,'http') || strstr($agent,'Scooter') || strstr($agent,'WebCopier')){$os='Spiders';
}else{$os='Unspecified';
}
return $os;
}

echo "
<html>
<head>
<title>test..</title>
</head>
<body>
<br>
<h2 align='center'>IP Information</h2>
<center>

Browser Name: $agent<br/>
Browser Version: $agent2<br />

Cookies Enabled: 		<script Language="JavaScript">
		
		</script>
<br/>
Platform: $os";
?>

Между другото сега потърсих в Интернет, виж и тези линкове може да ти помогнат:

php browser detection

get browser

Първия линк е скрипт мисля, защото можеше и да се свали.

Мерси много но в момента ми вади това:
Код:
IP Information

Browser Name: 
Browser Version: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4
Cookies Enabled: true 
Platform: Linux

Може ли да стане така:

Код:
IP Information

Browser Name: Chrome
Browser Version:  5.0.375.127 
Cookies Enabled: true 
Platform: Linux
[/code]
 
Така?

Код:
<?php
$os = getos();
function getos(){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($agent,'Win')){
if(strstr($agent,'NT 5.0') || strstr($agent,'NT5.0') || strstr($agent,'Windows 2000')){ 
$os = "Windows 2000";
}
else if(strstr($agent,'NT 5.1') || strstr($agent,'NT5.1') || strstr($agent,'Windows XP')){
$os = "Windows XP";
}
else if(strstr($agent,'Win98') || strstr($agent,'Windows 98')){
$os="Windows 98";
}
else if(strstr($agent,'NT')) {
$os='Windows NT';
}
else if(strstr($agent,'Win95') || strstr($agent,'Windows 95')){
$os='Windows 95';
}
else if(strstr($agent,'Win 9x')) {
$os='Windows 95';
}
else if(strstr($agent,'WinME') || strstr($agent,'Windows ME')){
$os='Windows ME';
}
else{
$os='Windows (version unspecified)';
}
}
else if (strstr($agent,'Mac')){
$os='Apple Macintosh';
}
else if (strstr($agent,'Linux')){
$os='Linux';
}
else if (strstr($agent,'BeOS')){
$os='BeOS';
}
else if (strstr($agent,'Unix') || strstr($agent, "HP-ux") || strstr($agent, "X11")){
$os='Unix';
}
else if (strstr($agent,'SunOS')){
$os='SunOS';
}
else if (strstr($agent,'FreeBSD')){
$os='FreeBSD';
}
else if (strstr($agent,'OpenBSD')){
$os='OpenBSD';
}
else if (strstr($agent,'IRIX')){
$os='IRIX';
}
else if (strstr($agent,'spider') || strstr($agent,'bot') || strstr($agent,'http') || strstr($agent,'Scooter') || strstr($agent,'WebCopier')){
$os='Spiders';
}
else{
$os='Unspecified';
}
return $os;
}
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (preg_match('/opera/', $userAgent)) {
$name = 'opera';
}
elseif (preg_match('/webkit/', $userAgent)) {
$name = 'safari';
}
elseif (preg_match('/msie/', $userAgent)) {
$name = 'msie';
}
elseif (preg_match('/Chrome/', $userAgent)) {
$name = 'Chrome';
}
elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
$name = 'Mozilla';
}
else {
$name = 'unrecognized';
}
if (preg_match('/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/', $userAgent, $matches)) {
$version = $matches[1];
}
else {
$version = 'unknown';
}
echo "
<html>
<head>
<title>test..</title>
</head>
<body>
<center>
Browser Name: $name<br />
Browser Version:  $version<br />
Cookies Enabled: <script Language=\"JavaScript\">
      
      </script><br />
Platform: $os ";
?>
 
<?php
$os = getos();
function getos(){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($agent,'Win')){
if(strstr($agent,'NT 5.0') || strstr($agent,'NT5.0') || strstr($agent,'Windows 2000')){
$os = "Windows 2000";
}
else if(strstr($agent,'NT 5.1') || strstr($agent,'NT5.1') || strstr($agent,'Windows XP')){
$os = "Windows XP";
}
else if(strstr($agent,'Win98') || strstr($agent,'Windows 98')){
$os="Windows 98";
}
else if(strstr($agent,'NT')) {
$os='Windows NT';
}
else if(strstr($agent,'Win95') || strstr($agent,'Windows 95')){
$os='Windows 95';
}
else if(strstr($agent,'Win 9x')) {
$os='Windows 95';
}
else if(strstr($agent,'WinME') || strstr($agent,'Windows ME')){
$os='Windows ME';
}
else{
$os='Windows (version unspecified)';
}
}
else if (strstr($agent,'Mac')){
$os='Apple Macintosh';
}
else if (strstr($agent,'Linux')){
$os='Linux';
}
else if (strstr($agent,'BeOS')){
$os='BeOS';
}
else if (strstr($agent,'Unix') || strstr($agent, "HP-ux") || strstr($agent, "X11")){
$os='Unix';
}
else if (strstr($agent,'SunOS')){
$os='SunOS';
}
else if (strstr($agent,'FreeBSD')){
$os='FreeBSD';
}
else if (strstr($agent,'OpenBSD')){
$os='OpenBSD';
}
else if (strstr($agent,'IRIX')){
$os='IRIX';
}
else if (strstr($agent,'spider') || strstr($agent,'bot') || strstr($agent,'http') || strstr($agent,'Scooter') || strstr($agent,'WebCopier')){
$os='Spiders';
}
else{
$os='Unspecified';
}
return $os;
}
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (preg_match('/opera/', $userAgent)) {
$name = 'opera';
}
elseif (preg_match('/webkit/', $userAgent)) {
$name = 'Chrome';
}
elseif (preg_match('/msie/', $userAgent)) {
$name = 'msie';
}
elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
$name = 'Mozilla';
}
else {
$name = 'unrecognized';
}
if (preg_match('/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/', $userAgent, $matches)) {
$version = $matches[1];
}
else {
$version = 'unknown';
}
echo "
<html>
<head>
<title>test..</title>
</head>
<body>
<center>
Browser Name: $name<br />
Browser Version: $version<br />
Cookies Enabled: <script Language=\"JavaScript\">

</script><br />
Platform: $os ";
?>
 
Karcho супер, но така версията е грешна трябва да е
5.0.375.127 а сега е

Browser Name: Chrome
Browser Version: 533.4
Cookies Enabled: true
Platform: Linux
 
<?php
$os = getos();
function getos(){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($agent,'Win')){
if(strstr($agent,'NT 5.0') || strstr($agent,'NT5.0') || strstr($agent,'Windows 2000')){
$os = "Windows 2000";
}
else if(strstr($agent,'NT 5.1') || strstr($agent,'NT5.1') || strstr($agent,'Windows XP')){
$os = "Windows XP";
}
else if(strstr($agent,'Win98') || strstr($agent,'Windows 98')){
$os="Windows 98";
}
else if(strstr($agent,'NT')) {
$os='Windows NT';
}
else if(strstr($agent,'Win95') || strstr($agent,'Windows 95')){
$os='Windows 95';
}
else if(strstr($agent,'Win 9x')) {
$os='Windows 95';
}
else if(strstr($agent,'WinME') || strstr($agent,'Windows ME')){
$os='Windows ME';
}
else{
$os='Windows (version unspecified)';
}
}
else if (strstr($agent,'Mac')){
$os='Apple Macintosh';
}
else if (strstr($agent,'Linux')){
$os='Linux';
}
else if (strstr($agent,'BeOS')){
$os='BeOS';
}
else if (strstr($agent,'Unix') || strstr($agent, "HP-ux") || strstr($agent, "X11")){
$os='Unix';
}
else if (strstr($agent,'SunOS')){
$os='SunOS';
}
else if (strstr($agent,'FreeBSD')){
$os='FreeBSD';
}
else if (strstr($agent,'OpenBSD')){
$os='OpenBSD';
}
else if (strstr($agent,'IRIX')){
$os='IRIX';
}
else if (strstr($agent,'spider') || strstr($agent,'bot') || strstr($agent,'http') || strstr($agent,'Scooter') || strstr($agent,'WebCopier')){
$os='Spiders';
}
else{
$os='Unspecified';
}
return $os;
}
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (preg_match('/opera/', $userAgent)) {
$name = 'opera';
}
elseif (preg_match('/webkit/', $userAgent)) {
$name = 'Chrome';
}
elseif (preg_match('/msie/', $userAgent)) {
$name = 'msie';
}
elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
$name = 'Mozilla';
}
else {
$name = 'unrecognized';
}
if (preg_match('/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/', $userAgent, $matches)) {
$version = $matches[2];
}
else {
$version = 'unknown';
}
echo "
<html>
<head>
<title>test..</title>
</head>
<body>
<center>
Browser Name: $name<br />
Browser Version: $version<br />
Cookies Enabled: <script Language=\"JavaScript\">

</script><br />
Platform: $os ";
?>
 
Код:
<?php
$os = getos();
function getos(){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($agent,'Win')){
if(strstr($agent,'NT 5.0') || strstr($agent,'NT5.0') || strstr($agent,'Windows 2000')){
$os = "Windows 2000";
}
else if(strstr($agent,'NT 5.1') || strstr($agent,'NT5.1') || strstr($agent,'Windows XP')){
$os = "Windows XP";
}
else if(strstr($agent,'Win98') || strstr($agent,'Windows 98')){
$os="Windows 98";
}
else if(strstr($agent,'NT')) {
$os='Windows NT';
}
else if(strstr($agent,'Win95') || strstr($agent,'Windows 95')){
$os='Windows 95';
}
else if(strstr($agent,'Win 9x')) {
$os='Windows 95';
}
else if(strstr($agent,'WinME') || strstr($agent,'Windows ME')){
$os='Windows ME';
}
else{
$os='Windows (version unspecified)';
}
}
else if (strstr($agent,'Mac')){
$os='Apple Macintosh';
}
else if (strstr($agent,'Linux')){
$os='Linux';
}
else if (strstr($agent,'BeOS')){
$os='BeOS';
}
else if (strstr($agent,'Unix') || strstr($agent, "HP-ux") || strstr($agent, "X11")){
$os='Unix';
}
else if (strstr($agent,'SunOS')){
$os='SunOS';
}
else if (strstr($agent,'FreeBSD')){
$os='FreeBSD';
}
else if (strstr($agent,'OpenBSD')){
$os='OpenBSD';
}
else if (strstr($agent,'IRIX')){
$os='IRIX';
}
else if (strstr($agent,'spider') || strstr($agent,'bot') || strstr($agent,'http') || strstr($agent,'Scooter') || strstr($agent,'WebCopier')){
$os='Spiders';
}
else{
$os='Unspecified';
}
return $os;
}
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (preg_match('/opera/', $userAgent)) {
$name = 'opera';
}
elseif (preg_match('/webkit/', $userAgent)) {
$name = 'Chrome';
}
elseif (preg_match('/msie/', $userAgent)) {
$name = 'msie';
}
elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
$name = 'Mozilla';
}
else {
$name = 'unrecognized';
}
if (preg_match('/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/', $userAgent, $matches)) {
$version = $matches[0];
}
else {
$version = 'unknown';
}
echo "
<html>
<head>
<title>test..</title>
</head>
<body>
<center>
Browser Name: $name<br />
Browser Version: $version<br />
Cookies Enabled: <script Language=\"JavaScript\">

</script><br />
Platform: $os ";
?>
 
Код:
<?php
$os = getos();
function getos(){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($agent,'Win')){
if(strstr($agent,'NT 5.0') || strstr($agent,'NT5.0') || strstr($agent,'Windows 2000')){
$os = "Windows 2000";
}
else if(strstr($agent,'NT 5.1') || strstr($agent,'NT5.1') || strstr($agent,'Windows XP')){
$os = "Windows XP";
}
else if(strstr($agent,'Win98') || strstr($agent,'Windows 98')){
$os="Windows 98";
}
else if(strstr($agent,'NT')) {
$os='Windows NT';
}
else if(strstr($agent,'Win95') || strstr($agent,'Windows 95')){
$os='Windows 95';
}
else if(strstr($agent,'Win 9x')) {
$os='Windows 95';
}
else if(strstr($agent,'WinME') || strstr($agent,'Windows ME')){
$os='Windows ME';
}
else{
$os='Windows (version unspecified)';
}
}
else if (strstr($agent,'Mac')){
$os='Apple Macintosh';
}
else if (strstr($agent,'Linux')){
$os='Linux';
}
else if (strstr($agent,'BeOS')){
$os='BeOS';
}
else if (strstr($agent,'Unix') || strstr($agent, "HP-ux") || strstr($agent, "X11")){
$os='Unix';
}
else if (strstr($agent,'SunOS')){
$os='SunOS';
}
else if (strstr($agent,'FreeBSD')){
$os='FreeBSD';
}
else if (strstr($agent,'OpenBSD')){
$os='OpenBSD';
}
else if (strstr($agent,'IRIX')){
$os='IRIX';
}
else if (strstr($agent,'spider') || strstr($agent,'bot') || strstr($agent,'http') || strstr($agent,'Scooter') || strstr($agent,'WebCopier')){
$os='Spiders';
}
else{
$os='Unspecified';
}
return $os;
}
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (preg_match('/opera/', $userAgent)) {
$name = 'opera';
}
elseif (preg_match('/webkit/', $userAgent)) {
$name = 'Chrome';
}
elseif (preg_match('/msie/', $userAgent)) {
$name = 'msie';
}
elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
$name = 'Mozilla';
}
else {
$name = 'unrecognized';
}
if (preg_match('/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/', $userAgent, $matches)) {
$exp = explode("/", $matches[0]);
$version = $exp[2];
}
else {
$version = 'unknown';
}
echo "
<html>
<head>
<title>test..</title>
</head>
<body>
<center>
Browser Name: $name<br />
Browser Version: $version<br />
Cookies Enabled: <script Language=\"JavaScript\">

</script><br />
Platform: $os ";
?>
 
Свали си browscap.ini и библиотеката за обработката му :)
Това е точно каквото ти трябва

Аз ползвам http://code.google.com/p/phpbrowscap/
 
Karcho сега дава :
Browser Name: Chrome
Browser Version: 533.4
Cookies Enabled: true
Platform: Linux

Благодаря за помоща за сега ще оставя темата отворена за да птобвам и на Alex95_bg_2 вариянта и ти давам точката

@Alex95_bg_2 може ли да дадеш малко инфо как точно се работи с browscap.ini
 
Теглиш
http://code.google.com/p/phpbrowscap/downloads/detail?name=Browscap-php5-r17.zip

Правиш папка cache, права 777

Правиш си пхп файл

Код:
<?php

require Browscap.php';

$bc = new Browscap('./cache');

$current_browser = $bc->getBrowser();

echo '<pre>';
print_r($current_browser);
echo '</pre>';

И го пускаш. Първия път ще се забави.
Можеш да сложиш browscap.ini в cache но сега погледнах класа и май сам ще си свали ini-то също.
 

Back
Горе