如何通过PHP获得屏幕宽度? [英] how to get screen width through php?

查看:908
本文介绍了如何通过PHP获得屏幕宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道PHP是服务器端的事情......但我想知道如何通过PHP得到用户的屏幕宽度。 我在网上搜索一下,他们说我必须使用JavaScript和PHP在一起。 但我不如何做的工作。 请告诉我,最简单的方法,通过PHP来获取用户的屏幕宽度。 如果可以通过JavaScript做才告诉我怎么去的JavaScript的宽度变量传递给整数格式(而不是字符串)的PHP变量。

Hi i know that php is server side thing... but i want know how to get user screen width through php. i search on the net, they says i have to use javascript and php together. but i don't how to make work. please tell me in simplest way to get the screen width of the user through php. if it can done through javascript only then tell me the way to pass the width variable of the javascript to the php variable in integer format(not string).

请告诉我codeS做...我真的搞砸了这一切...... 感谢:)

please show me codes to do it... i'm really messed up in all this... thanks :)

推荐答案

不可能完全 PHP 您可能需要使用的JavaScript 太 反正试试这个

Not possible with complete php you might need to use javascript too Anyway try this

<?php
session_start();
if(isset($_SESSION['screen_width']) AND isset($_SESSION['screen_height'])){
    echo 'User resolution: ' . $_SESSION['screen_width'] . 'x' . $_SESSION['screen_height'];
} else if(isset($_REQUEST['width']) AND isset($_REQUEST['height'])) {
    $_SESSION['screen_width'] = $_REQUEST['width'];
    $_SESSION['screen_height'] = $_REQUEST['height'];
    header('Location: ' . $_SERVER['PHP_SELF']);
} else {
    echo '<script type="text/javascript">window.location = "' . $_SERVER['PHP_SELF'] . '?width="+screen.width+"&height="+screen.height;</script>';
}
?>

这篇关于如何通过PHP获得屏幕宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆