webForumDet fria alternativet

Browser check som inte funkar riktigt.

PHP

2 svar · 195 visningar · startad av UrMe

Medlem sedan apr. 2001762 inlägg
Frågan#1

Hittade koden HÄR.
Bland kommentarerna ganska långt ner.
Men det vill inte funka.. får inge felmeddelande eller nån utskrift alls.. nån som har nån lösning?

global $HTTP_USER_AGENT, $BName, $BVersion, $BPlatform; 
function detect_browser() 
{ 
global $HTTP_USER_AGENT, $BName, $BVersion, $BPlatform; 

// Browser 
if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}",$HTTP_USER_AGENT,$match) || eregi("(opera/)([0-9]{1,2}.[0-9]{1,3}){0,1}",$HTTP_USER_AGENT,$match)) 
{ 
$BName = "Opera"; $BVersion=$match[2]; 
} 
elseif(eregi("(konqueror)/([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 
{ 
$BName = "Konqueror"; $BVersion=$match[2]; 
} 
elseif(eregi("(lynx)/([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})",$HTTP_USER_AGENT,$match)) 
{ 
$BName = "Lynx "; $BVersion=$match[2]; 
} 
elseif(eregi("(links) \(([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 
{ 
$BName = "Links "; $BVersion=$match[2]; 
} 
elseif(eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 
{ 
$BName = "MSIE "; $BVersion=$match[2]; 
} 
elseif(eregi("(netscape6)/(6.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 
{ 
$BName = "Netscape "; $BVersion=$match[2]; 
} 
elseif(eregi("mozilla/5",$HTTP_USER_AGENT)) 
{ 
$BName = "Netscape"; $BVersion="Unknown"; 
} 
elseif(eregi("(mozilla)/([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 
{ 
$BName = "Netscape "; $BVersion=$match[2]; 
} 
elseif(eregi("w3m",$HTTP_USER_AGENT)) 
{ 
$BName = "w3m"; $BVersion="Unknown"; 
} 
else{$BName = "Unknown"; $BVersion="Unknown";} 

// System 
if(eregi("linux",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "Linux"; 
} 
elseif(eregi("win32",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "Windows"; 
} 
elseif((eregi("(win)([0-9]{2})",$HTTP_USER_AGENT,$match)) || (eregi("(windows) ([0-9]{2})",$HTTP_USER_AGENT,$match))) 
{ 
$BPlatform = "Windows $match[2]"; 
} 
elseif(eregi("(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) 
{ 
$BPlatform = "Windows NT $match[2]"; 
} 
elseif(eregi("(windows nt)( ){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) 
{ 
$BPlatform = "Windows NT $match[3]"; 
} 
elseif(eregi("mac",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "Macintosh"; 
} 
elseif(eregi("(sunos) ([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) 
{ 
$BPlatform = "SunOS $match[2]"; 
} 
elseif(eregi("(beos) r([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) 
{ 
$BPlatform = "BeOS $match[2]"; 
} 
elseif(eregi("freebsd",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "FreeBSD"; 
} 
elseif(eregi("openbsd",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "OpenBSD"; 
} 
elseif(eregi("irix",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "IRIX"; 
} 
elseif(eregi("os/2",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "OS/2"; 
} 
elseif(eregi("plan9",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "Plan9"; 
} 
elseif(eregi("unix",$HTTP_USER_AGENT) || eregi("hp-ux",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "Unix"; 
} 
elseif(eregi("osf",$HTTP_USER_AGENT)) 
{ 
$BPlatform = "OSF"; 
} 
else{$BPlatform = "Unknown";} 

 
echo $HTTP_USER_AGENT; 
echo $BName; 
echo $BVersion; 
echo $BPlatform; 
 
}

------------------
You play by the rules, you die by the rules

Medlem sedan apr. 2001762 inlägg
#2

Jag löste det! Tack ändå!

------------------
You play by the rules, you die by the rules

Medlem sedan juli 200159 inlägg
#3

En rekomendation är att INTE använda reuljära uttryck utan istället använda ex strstr så länge det går.
Reguljära uttryck startar ett kärnkraftverk på servern och för enklare uttryck behövs det ofta inte.

Ex:

function isWindows()
{
global $HTTP_USER_AGENT;

if(strstr($HTTP_USER_AGENT, "Windows"))
{
return true;
}
else // ej windows
{
return false;
}
}

------------------
Kodarkivet
----------------------
http://www.quickmess.com/kodarkivet

259 ms totalt · 4 externa anrop · v20260731065814-full.868a69e5
126 ms — deklarationer (db)
0 ms — hämta statistik (cache)
129 ms — hämta tråd, inlägg och bilagor (db)
126 ms — ändringar (db)