What's the best way to detect a browser with php?

后端 未结 5 983
我在风中等你
我在风中等你 2021-01-21 08:13

Could anyone tell me the best way to detect a browser using php? IE 6 and 7 are terrible when it comes to achieving full browser compatibility with CSS so my site isn\'t going t

5条回答
  •  無奈伤痛
    2021-01-21 09:05

    The best way to detect the user's browser with PHP is to not check the user's browser with PHP.

    You've mentioned that IE lt 8 sucks for CSS (and that is something every web dev can agree on), the best way to tell the user that their browser is too old is with a conditional comment in the HTML:

    
    ...
    
    
    
    
    ...
    
    

    The code I've written shows two things you can do: first it shows you can set an IE only stylesheet, and secondly it shows you can set IE only chunks of HTML.

    I see no reason you can't allow your IE users to use your wobsite, if it doesn't work, just let them know that it's their own fault for using a crummy browser.

    This will also allow you to set a cookie for subsequent PHP calls:

    
    

提交回复
热议问题