Sep
26
Posted on September 26, 2008 by Dayson Pais (PHP, WebDev)

Sometimes you may want to display some part of the page/code only to IE users. Especially when you may be using some png fix javascript files or the famous iepngfix.htc for IE6 clients. This php function lets you identify an IE browser loading your page:

Example:

<?php
    if(detect_ie())
    { //if internet explorer 6 being used, then apply IE png fix
    ?>
        <!--Begin IE PNG Fix-->
        <style type="text/css">
        #shadow_tp, #shadow_btm {
            behavior: url(iepngfix.htc)
        }
        </style>
        <!--End IE PNG Fix-->        
    <?php
    }
?>

Function:

<?php
	function detect_ie()
	{
		if (isset($_SERVER['HTTP_USER_AGENT']) && 
		(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
			return true;
		else
			return false;
	}
?>
    Print Version    

Comments

Fear on 3 October, 2008 at 5:23 am #

If you’re not into php and need a more robust method ->http://www.quirksmode.org/js/detect.html


Sander on 5 February, 2009 at 8:04 pm #

Why is it more robust to use a Javascript solution Fear? You can’t fool the headers that easily with IE6 and those users who do it, probably know very good that there are better version around than that awful browser!


Dayson Pais on 8 February, 2009 at 4:10 pm #

Fooling the headers as to which browser you are is anyway not going to create a security exploit. Just the page may appear in an unexpected fashion… Well, you asked for it ? ;)

Good point Sander. Detecting browsers in the header is always the best option though frameworks like jQuery seem to have made this more advanced.


Post a Comment
Name:
Email:
Website:
Comments: