fullyloaded Posted January 3, 2012 Share Posted January 3, 2012 hi i was wondering if anyone has any idea how to get this code to work for more then one browser? i can get it to work for one browser but have no luck on getting it to work for more then one browser thanks... code that don't work: <?php include("browserDetection.php"); $user_browser = browser_detection('browser'); if ( $user_browser == 'mozilla' ) { echo("<link href='style.css' type='text/css' rel='stylesheet'></link>\n"); } else { echo("<link href='style1.css' type='text/css' rel='stylesheet'></link>\n"); } if ( browser_detection('msie') ) { echo("<link href='style.css' type='text/css' rel='stylesheet'></link>\n"); } else { echo("<link href='style1.css' type='text/css' rel='stylesheet'></link>\n"); } ?> code that works: <?php include("browserDetection.php"); $user_browser = browser_detection('browser'); if ( $user_browser == 'Mozilla' ) { echo("<link href='style.css' type='text/css' rel='stylesheet'></link>\n"); } else { echo("<link href='style1.css' type='text/css' rel='stylesheet'></link>\n"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254263-detected-browser/ Share on other sites More sharing options...
trq Posted January 3, 2012 Share Posted January 3, 2012 It would help if you told us what browser_detection() actually returns. Quote Link to comment https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303633 Share on other sites More sharing options...
fullyloaded Posted January 3, 2012 Author Share Posted January 3, 2012 hi here it is sorry browser_detection code: <?php function browser_detection( $which_test ) { $browser = ''; $dom_browser = ''; $navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : ''; if (stristr($navigator_user_agent, "mozilla")) { $browser = 'mozilla'; $dom_browser = true; } 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; } else { $dom_browser = false; $browser = false; } if ( $which_test == 'browser' ) { return $browser; } elseif ( $which_test == 'dom' ) { return $dom_browser; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303834 Share on other sites More sharing options...
ManiacDan Posted January 3, 2012 Share Posted January 3, 2012 And now to define what you mean by "doesn't work." Quote Link to comment https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303852 Share on other sites More sharing options...
PaulRyan Posted January 3, 2012 Share Posted January 3, 2012 I believe he wants to display a different style sheet for each browser. <?PHP include("browserDetection.php"); //### Send the user agent to the function for it to return a correct value $user_browser = browser_detection($_SERVER['HTTP_USER_AGENT']); if ( $user_browser == 'mozilla' ) // If mozilla, show mozilla style sheet { echo("<link href='style-mozilla.css' type='text/css' rel='stylesheet'></link>\n"); } else if ( $user_browser == 'msie' ) // If internet explorer, show ie style sheet { echo("<link href='style-ie.css' type='text/css' rel='stylesheet'></link>\n"); } else // If another browser, show other style sheet { echo("<link href='style-other.css' type='text/css' rel='stylesheet'></link>\n"); } ?> Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303856 Share on other sites More sharing options...
fullyloaded Posted January 3, 2012 Author Share Posted January 3, 2012 Thanks PaulRyan that worked great. Quote Link to comment https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303857 Share on other sites More sharing options...
ManiacDan Posted January 3, 2012 Share Posted January 3, 2012 You should probably be using a real browser detector like this one. Quote Link to comment https://forums.phpfreaks.com/topic/254263-detected-browser/#findComment-1303859 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.