Dorky Posted October 5, 2009 Share Posted October 5, 2009 i have been trying so herd to figure out how to find, isolate, and $var the msie ver from user agent, i have lloked over strstr, strpos, in_array, and so many others. all i want is to put the msie versions into an array and compare that to the user agent string. it sounds so simple yet i cannot find it. but i did find a few forums they let you sign up before telling you they think im going to pay them for their forum lol. Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/ Share on other sites More sharing options...
yettti Posted October 5, 2009 Share Posted October 5, 2009 so you want to be able to get the msie version number and put it into a variable if so i think that this may help you... i haven't tried it but i think it would work i got this from: http://us2.php.net/manual/en/function.get-browser.php $browser = get_browser(null, true); echo $browser['version']; may need some changes but i hope i pointed you in the right direction Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931057 Share on other sites More sharing options...
Dorky Posted October 5, 2009 Author Share Posted October 5, 2009 yes that would be just what the doctor ordered but my host wont install any libs outside what they already have and i dont have enough clients to support the cost of a dedicated or vpn. so i need to do this with standard php5. so you want to be able to get the msie version number and put it into a variable if so i think that this may help you... i haven't tried it but i think it would work i got this from: http://us2.php.net/manual/en/function.get-browser.php $browser = get_browser(null, true); echo $browser['version']; may need some changes but i hope i pointed you in the right direction Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931070 Share on other sites More sharing options...
yettti Posted October 5, 2009 Share Posted October 5, 2009 Try having a look at the notes on the get_browser() page. There are some examples of functions that use Regex to find the browser name and version number, they might be worth a try... Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931082 Share on other sites More sharing options...
thebadbad Posted October 5, 2009 Share Posted October 5, 2009 Try something like <?php if (preg_match('~MSIE ([^;]+);~', $_SERVER['HTTP_USER_AGENT'], $match)) { echo 'Internet Explorer version: ' . htmlentities($match[1]); } else { echo 'Browser isn\'t Internet Explorer'; } ?> I'm using htmlentities() because the user agent string can be spoofed by the user, potentially containing malicious code to be executed. Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931086 Share on other sites More sharing options...
Dorky Posted October 5, 2009 Author Share Posted October 5, 2009 i have looked but i would rather find the command for finding a string(by array) within a string(string). im sure there is a command for this without using 200 lines of code to circumvent knowing the proper command to do so. this is a useful way of comparing for future applications outside of my current project. just trying to learn thx Try having a look at the notes on the get_browser() page. There are some examples of functions that use Regex to find the browser name and version number, they might be worth a try... Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931090 Share on other sites More sharing options...
Dorky Posted October 5, 2009 Author Share Posted October 5, 2009 WOW. ok can you break down this part for me so i understand what this means '~MSIE ([^;]+);~' Try something like <?php if (preg_match('~MSIE ([^;]+);~', $_SERVER['HTTP_USER_AGENT'], $match)) { echo 'Internet Explorer version: ' . htmlentities($match[1]); } else { echo 'Browser isn\'t Internet Explorer'; } ?> I'm using htmlentities() because the user agent string can be spoofed by the user, potentially containing malicious code to be executed. Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931095 Share on other sites More sharing options...
Dorky Posted October 5, 2009 Author Share Posted October 5, 2009 allow me to expand on this project. i am using a lot of css2 and some css3. to keep my site from being viewed improperly i am filtering pre-mozilla5 browsers but need to allow for ie8 but it uses mozilla4 so its been hard for me to find a way to make an exception for ie8. this is what i have so far. feel free to edit or comment on this $browserfind = $_SERVER['HTTP_USER_AGENT'] ; $firstoc = strpos($browserfind, '.'); $browser = substr($browserfind, 0, $firstoc ); $listbrowsers = array("Mozilla/4" , "Mozilla/5" , "Opera/9" , "Yandex/1" , "facebookexternalhit/1"); $redirect="http://studio378d.com?sorry&btype=$browser"; if (!in_array( "$browser" , $listbrowsers , true)) { header("Location: $redirect"); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931105 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 Search the string for the string 'MSIE ' followed by any character except semi-colon, untill you find semicolon and return the value between 'MSIE ' and semicolon. Quote Link to comment https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931108 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.