Alan Horvath Posted October 18, 2009 Share Posted October 18, 2009 I was having a problem with Internet Exploder (big surprise, right?) displaying my drop down menus improperly. I found a solution that works ... I have a PHP file that I place as an include on all my pages and the drop down menus, on IE, are cool. But my problem, at present, is this: I need to have that PHP Include (for IE) loaded, in place of my regular PHP Include (for all the other browsers), when some one is using the IE browser. Is there a way to write an "If IE" conditional statement for a PHP Include? Thanks for your help! Alan Quote Link to comment https://forums.phpfreaks.com/topic/178127-php-include-wif-ie-condition-statement/ Share on other sites More sharing options...
cags Posted October 18, 2009 Share Posted October 18, 2009 Same way you'd do any normal if else stament... if($is_IE) { include 'ie.php'; } else { include 'other.php'; } You could probably shorten that up using the terniary operator if you wanted to. Quote Link to comment https://forums.phpfreaks.com/topic/178127-php-include-wif-ie-condition-statement/#findComment-939185 Share on other sites More sharing options...
mrMarcus Posted October 18, 2009 Share Posted October 18, 2009 #user agent sniffer; $user_agent = (isset ($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); if (strpos ($user_agent, 'MSIE') !== false) { include 'ie.php'; } else { include 'other.php'; } Quote Link to comment https://forums.phpfreaks.com/topic/178127-php-include-wif-ie-condition-statement/#findComment-939191 Share on other sites More sharing options...
Daniel0 Posted October 18, 2009 Share Posted October 18, 2009 Generally speaking, user agent sniffing is a bad idea. It breaks forward compatibility and it's the reason why why modern user agent string are long and cryptic. Quote Link to comment https://forums.phpfreaks.com/topic/178127-php-include-wif-ie-condition-statement/#findComment-939205 Share on other sites More sharing options...
Alan Horvath Posted October 19, 2009 Author Share Posted October 19, 2009 I found one that works. This goes into "index.php" (and *nothing* else): <?php if (eregi("MSIE", $_SERVER['HTTP_USER_AGENT'])) { $location = 'http://somesite.com/index_ie.php'; header ("location: $location"); exit(); } else { $otherlocation = 'http://somesite.com/index_allothers.php'; header ("location: $otherlocation"); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/178127-php-include-wif-ie-condition-statement/#findComment-939410 Share on other sites More sharing options...
mrMarcus Posted October 19, 2009 Share Posted October 19, 2009 I found one that works.the code i provided "works". did you even try it? Quote Link to comment https://forums.phpfreaks.com/topic/178127-php-include-wif-ie-condition-statement/#findComment-939423 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.