可以php检测客户端浏览器监控大小/分辨率?

9 php resolution detect

Php可以检测IP,主机名,客户端代理等.可以通过php检测客户端浏览器的监控大小/分辨率吗?

Pau*_*ams 25

不,它不能.PHP在服务器上运行,因此它无法检测客户端设置,除非您采取特定的客户端步骤将信息传递给服务器上的PHP脚本.


Dav*_*man 5

请注意,我们中的一些人喜欢我们的浏览器非最大化.也许你最好不要试图检测浏览器大小而不是屏幕分辨率.我假设要做的任何一个JS都非常相似,但我实际上并不知道是这样的.

另外,盲人的屏幕阅读器的分辨率是多少?

  • +1.我有2560x1600的屏幕分辨率,我几乎从不运行最大化.您应该阅读视图端口大小(窗口区域不包括工具栏,滚动条,状态栏和窗口装饰). (2认同)

sch*_*der 4

您必须将 PHP 与 JavaScript 一起使用,如下所示:

$url = $_SERVER['PHP_SELF'];

if( isset($HTTP_COOKIE_VARS["res"]) )
    $res = $HTTP_COOKIE_VARS["res"];

else {
    ?>
    <script language="javascript">
    <!--
    go();

    function go() 
    {
        var today = new Date();
        var the_date = new Date("August 31, 2020");
        var the_cookie_date = the_date.toGMTString();
        var the_cookie = "res="+ screen.width +"x"+ screen.height;
        var the_cookie = the_cookie + ";expires=" + the_cookie_date;
        document.cookie=the_cookie
            location = '<?echo "$url";?>';
    }
    //-->
    </script>
    <?php
}

//Let's "split" the resolution results into two variables
list($width, $height) = split('[x]', $res);

//Take the width and height minus 300
$tb_width = $width-300;
$tb_height = $height-300;

//Make the table
print("<table align=center border=1 width=" .$tb_width . " height=" . $tb_height . " >
    <tr><td align=center>Your screen resolution is " . $width . " by " . $height . ".<br>
    The width/height of this table is " . $tb_width . " by " . $tb_height . ".</td></tr>
    </table>");
Run Code Online (Sandbox Code Playgroud)