Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    Php check browser

    My code doesn't work and I'm not sure why. It is supposed to check whether someone is using IE. I'm trying to do this the fastest way possible, so help would be appreciated.
    PHP Code:
    <?php
    if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") === TRUE)
    {
    echo 
    "IE.";
    }
    else
    {
    echo 
    "something better";
    }
    ?>
    This is always returning "something better" even if viewed in IE. Any ideas why?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,028
    Thanks
    2
    Thanked 315 Times in 307 Posts
    strpos will return FALSE if it does not find a match or it will return an integer value which is the start of the first occurrence it finds. It will never return a match for === TRUE
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    so i just need to switch the order of everything. Okay

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,634
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Of course most browsers will claim to be IE so that crappy old scripts that test for what browser it is rather than what the browser needs to support will still work.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    You can see the check in action here: http://dev.powerwd.com/AXClan/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •