Smackie Posted April 29, 2008 Share Posted April 29, 2008 Hello I'm just curious if there is a way to get PHP only to work with Firefox and IE7 but restrict from ie6. and if it is possible could someone show me a tutorial on this? I been meaning to look into it but Busy times doesn't help lol. Thank you Smackie Link to comment https://forums.phpfreaks.com/topic/103455-php-with-ie7-and-firefox/ Share on other sites More sharing options...
dezkit Posted April 29, 2008 Share Posted April 29, 2008 This is not a php code, rather javascript. When you put this into your index.php in your website, it will redirect the person if their browser isn't IE7 to error.html Code is not tested and got it from google, if you wanna learn more just google "dynamicdrive browser redirect" <script> var browser_type=navigator.appName var browser_version=parseInt(navigator.appVersion) else if (browser_type=="Microsoft Internet Explorer"&&browser_version<=6) window.location.replace("error.html") else window.location="http://www.website.com/welcome/" </script> Link to comment https://forums.phpfreaks.com/topic/103455-php-with-ie7-and-firefox/#findComment-529771 Share on other sites More sharing options...
craygo Posted April 29, 2008 Share Posted April 29, 2008 Not sure why you would but you can try this function here. <?php function browser_detection( $which_test ) { // initialize the variables $browser = ''; $dom_browser = ''; // set to lower case to avoid errors, check to see if http_user_agent is set $navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : ''; // run through the main browser possibilities, assign them to the main $browser variable if (stristr($navigator_user_agent, "opera")) { $browser = 'opera'; $dom_browser = true; } elseif (stristr($navigator_user_agent, "msie 4")) { $browser = 'msie4'; $dom_browser = false; } elseif (stristr($navigator_user_agent, "msie 6")) { $browser = 'msie6'; $dom_browser = false; } elseif (stristr($navigator_user_agent, "msie 7")) { $browser = 'msie7'; $dom_browser = false; } elseif (stristr($navigator_user_agent, "msie")) { $browser = 'msie'; $dom_browser = true; } elseif ((stristr($navigator_user_agent, "konqueror")) || (stristr($navigator_user_agent, "safari"))) { $browser = 'safari'; $dom_browser = true; } elseif (stristr($navigator_user_agent, "gecko")) { $browser = 'mozilla'; $dom_browser = true; } elseif (stristr($navigator_user_agent, "mozilla/4")) { $browser = 'ns4'; $dom_browser = false; } else { $dom_browser = false; $browser = false; } // return the test result you want if ( $which_test == 'browser' ) { return $browser; } elseif ( $which_test == 'dom' ) { return $dom_browser; // note: $dom_browser is a boolean value, true/false, so you can just test if // it's true or not. } } $user_browser = browser_detection("browser"); if($user_browser == "msie6"){ echo "no soup for you"; } ?> Ray Now just check for the Link to comment https://forums.phpfreaks.com/topic/103455-php-with-ie7-and-firefox/#findComment-529803 Share on other sites More sharing options...
thebadbad Posted April 29, 2008 Share Posted April 29, 2008 I've been using this snippet to message IE6 users: <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) { //do something when user agent is IE6 } ?> or the other way around <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') === false) { //do something when user agent is anything but IE6 } ?> Link to comment https://forums.phpfreaks.com/topic/103455-php-with-ie7-and-firefox/#findComment-529835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.