realmoflegends Posted June 1, 2015 Share Posted June 1, 2015 Hey all, Just having an issue about how to implement this code. I've googled, and read many articles about it, and can't put it together. I need a line of code to run, but ONLY if a user is using Internet Explorer or Chrome as their browser. What would be the best way to do this? Thanks! Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted June 1, 2015 Share Posted June 1, 2015 Never tried such but here is a link that may help you http://php.net/manual/en/function.get-browser.php Quote Link to comment Share on other sites More sharing options...
sniko Posted June 1, 2015 Share Posted June 1, 2015 Just to throw this into the mix, a user agent string is supplied by the user (ie: you), and this string is easily spoofed so you can't rely on it too much. Though, it depends what you need to detect it for. [MENTION=65073]lucky3809[/MENTION] has a nice solution, let's build on it. $objBrowser = get_browser(); if( in_array( strtolower($objBrowser->browser), array('chrome', 'msie') )) { echo 'We detected you\'re using either chrome or internet explorer'; die; } echo 'You\'re okay'; Because get_browser() requires some extra configuration (outlined in the manual), it may be better (depending on your access level on the server) to use a solution like this: http://stackoverflow.com/questions/5302302/php-if-internet-explorer-6-7-8-or-9 Quote Link to comment Share on other sites More sharing options...
G7470 Posted June 1, 2015 Share Posted June 1, 2015 I would personally prefer using the preg_match solution that sniko has linked to in the second solution. No extra configuration required and uses the defined server variables. ~G7470 Quote Link to comment Share on other sites More sharing options...
Guest Posted June 1, 2015 Share Posted June 1, 2015 I would personally prefer using the preg_match solution that sniko has linked to in the second solution. No extra configuration required and uses the defined server variables. ~G7470 You realise it makes no difference? The content in the server variable is still given to it by the user... therefore still could be false Quote Link to comment Share on other sites More sharing options...
sniko Posted June 1, 2015 Share Posted June 1, 2015 You realise it makes no difference? The content in the server variable is still given to it by the user... therefore still could be false Yes, but you'd need extra configuration on the server to get get_browser() to work. [MENTION=70485]G7470[/MENTION] was saying he prefers the other method (ie: not get_browser()). He wasn't saying that it's more reliable in the sense of what it brings back. Quote Link to comment Share on other sites More sharing options...
realmoflegends Posted June 1, 2015 Author Share Posted June 1, 2015 Solved with a simple CSS fix, thanks to the great Sniko. :) Quote Link to comment 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.