eevan79 Posted August 24, 2010 Share Posted August 24, 2010 Here is my simple script for user browser and OS detection: $agent = $_SERVER['HTTP_USER_AGENT']; if (strstr($agent,"Windows")) {$os = "Windows";} if (strstr($agent,"Windows NT 6")) {$os = "Windows 7";} if (strstr($agent,"Linux")) {$os = "Linux";} if (strstr($agent,"Intel Mac OS X")) {$os = "OS X";} if (strstr($agent,"OpenBSD")) {$os = "BSD";} if (strstr($agent,"FreeBSD")) {$os = "FreeBSD";} if (strstr($agent,"Firefox/3")) {$br = "Firefox 3";} if (strstr($agent,"Firefox/2")) {$br = "Firefox 2";} if (strstr($agent,"Firefox/1")) {$br = "Firefox 1";} if (strstr($agent,"Phoenix/")) {$br = "Phoenix (Mozilla lite)";} if (strstr($agent,"MSIE 6")) {$br = "IE 6";} if (strstr($agent,"MSIE 7")) {$br = "IE 7";} if (strstr($agent,"MSIE 8")) {$br = "IE 8";} if (strstr($agent,"Netscape6/6")) {$br = "Netscape 6";} if (strstr($agent,"Opera")) {$br = "Opera";} if (strstr($agent,"Opera") and strstr($agent,"Version/10")) {$br = "Opera 10";} if (strstr($agent,"Opera") and strstr($agent,"Version/9")) {$br = "Opera 9";} if (strstr($agent,"Chrome") and strstr($agent,"Chrome/5")) {$br = "Chrome 5";} if (strstr($agent,"Safari/")) {$br = "Safari";} if (strstr($agent,"Safari/") and strstr($agent,"Version/5")) {$br = "Safari 5";} if (strstr($agent,"Safari/") and strstr($agent,"Version/4")) {$br = "Safari 4";} if (strstr($agent,"Safari/") and strstr($agent,"Version/3")) {$br = "Safari 3";} if (strstr($agent,"SeaMonkey/") and strstr($agent,"Gecko")) {$br = "SeaMonkey";} echo "Browser: <b>$br</b>, OS: <b>$os</b>"; I found some information from here: http://www.zytrax.com/tech/web/browser_ids.htm Is there any better solution for this, or script above is accurate? Quote Link to comment https://forums.phpfreaks.com/topic/211629-browser-detection-suggestion/ Share on other sites More sharing options...
RussellReal Posted August 24, 2010 Share Posted August 24, 2010 you should look into browscap, I never worked with it before but I have actually ran into it a couple times, it should actually help you alot, and there are TONS of browscap.ini downloads across the internet Quote Link to comment https://forums.phpfreaks.com/topic/211629-browser-detection-suggestion/#findComment-1103240 Share on other sites More sharing options...
eevan79 Posted August 24, 2010 Author Share Posted August 24, 2010 Thanks, I have searched for some browser caps, and its basicaly user_agent database . I dont need so much information, just for most used browsers and OS. Also, I have tested this script above with different browsers and OS and its working fine. If anyone have better suggestion, feel free to share with us. Quote Link to comment https://forums.phpfreaks.com/topic/211629-browser-detection-suggestion/#findComment-1103283 Share on other sites More sharing options...
RussellReal Posted August 24, 2010 Share Posted August 24, 2010 browscap is an ini file full of browsers and information about them, if you want to include a huge chunk of unattractive if statements for user agents than you'd do it your way browscap is the best alternative to this.. and probably better than what you've got going because new browscap.ini files come out whenever a new browser comes out.. + you only check for what 10 browsers? most browscap.ini variations have pretty much every distributed browser besides homemade ones from kids with visual basic.. ALSO your checks are pretty redundant in the way that if it alrdy matches "windows 7" why would you check for linux.. you feel me? Quote Link to comment https://forums.phpfreaks.com/topic/211629-browser-detection-suggestion/#findComment-1103375 Share on other sites More sharing options...
eevan79 Posted August 25, 2010 Author Share Posted August 25, 2010 Ok, I understand. Anyway, I just want to make small stats for users and their OS/Browsers. Dont need huge browsers database. For example: FF - 45%, IE - 15%, Opera - 25%, Netscape - 5% and same for OS (Win - Xp/7/98, Linux... ) . I can also try this with browcap. Solved and thanks for suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/211629-browser-detection-suggestion/#findComment-1103411 Share on other sites More sharing options...
bulrush Posted September 13, 2010 Share Posted September 13, 2010 My server, which I do not control, does not have a browsecap file so I can't use that. Hence, I need this guy's series of IF/THEN statements just to get me somewhere in the ballpark. Quote Link to comment https://forums.phpfreaks.com/topic/211629-browser-detection-suggestion/#findComment-1110577 Share on other sites More sharing options...
RussellReal Posted September 19, 2010 Share Posted September 19, 2010 My server, which I do not control, does not have a browsecap file so I can't use that. Hence, I need this guy's series of IF/THEN statements just to get me somewhere in the ballpark. you probably would want to change it to if/else then instead of if if if if ;P Quote Link to comment https://forums.phpfreaks.com/topic/211629-browser-detection-suggestion/#findComment-1112687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.