Jump to content
MakeWebGames

Need help with a section of code


Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...