Jump to content

isolating msie ver.


Dorky

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931057
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931070
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931086
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931090
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931095
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/176611-isolating-msie-ver/#findComment-931105
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.