0

我对php很陌生,所以请耐心等待:)

我正在尝试创建一个可以使用get_user_browserphp 中的函数的网页,然后将用户定向到单独的 HTML 页面。

我的网站是http://www.danabohne.com,我刚刚意识到它在 IE 中几乎不可见。除非有不同的方法来解决这个问题,否则我想制作一个单独的静态 HTML 站点,IE 用户可以看到。

任何反馈都会非常有帮助!

4

2 回答 2

1

Firstly, it's important to note that browser detection on the server is not recommended, because it is possible for browsers to provide false user agent details, or none at all. (I know of some firewall products that routinely strip out this kind of data from the http headers).

Secondly, the get_user_browser function only works if you have a valid browsecap.ini file. If you're having trouble getting the function to work, check that you have this ini file and that it is up-to-date. (also note that you will need to keep it updated whenever new browsers or browser versions are released).

Finally, most (virtually all) IE-specific display issues can be resolved without having to create a separate page for IE.

Specifically in your case, I can see what the problem is straight away when looking at the HTML source code for your page:

The problem is the <pre></pre> that is in the first line of your code immediately before the <!DOCTYPE>. I assume this is the left-overs from some debugging code that hasn't been removed properly.

This <pre></pre> is going to cause IE to fall into "quirks mode", because IE sees the <pre> and assumes it doesn't have a doctype. Without a doctype, IE assumes the page should be in quirks mode.

Quirks mode makes IE's rendering engine display the page completely differently (it's basically an IE5-backward-compatibility mode), so it's no wonder your page looks rubbish in IE.

This behaviour is the same in all versions of IE.

If you have other IE-specific problems, it would be better to try to fix them on the page, as there are a lot of tools and hacks available to make IE work better.

Hope that helps.

于 2012-05-10T20:05:05.737 回答
1
<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];  
if( strpos($useragent,"MSIE 6.0") ) { 

  header("Location: http://google.com"); 

}
?>

您可以根据需要添加更多if条件。

但是,就像评论中提到的约翰一样。我建议您创建一个单独的样式表并创建一个后备设计,而不是重定向到另一个页面。

于 2012-05-10T19:47:21.610 回答