Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php获取窗口大小_Php_Size - Fatal编程技术网

使用php获取窗口大小

使用php获取窗口大小,php,size,Php,Size,此代码存在什么问题: $window_width= '<script>screen.availWidth</script>'; $window_height= '<script>screen.availHeight</script>'; $window_width='screen.availWidth'; $window_height='screen.availHeight'; 有什么想法吗?您似乎误解了PHP和HTML/JavaScript如

此代码存在什么问题:

$window_width= '<script>screen.availWidth</script>';
$window_height= '<script>screen.availHeight</script>';
$window_width='screen.availWidth';
$window_height='screen.availHeight';

有什么想法吗?

您似乎误解了PHP和HTML/JavaScript如何协同工作的基本概念。PHP是服务器端语言,JavaScript是客户端语言

PHP首先生成输出,然后将其传输到执行它的客户端。你想用另一种方式来做


您需要做的是,首先,使用PHP生成一个页面,将其发送到客户端执行,然后让JavaScript执行一个调用,使用GET/POST请求将信息发送回PHP。

代码中没有错误,但无法在PHP变量中获取任何值,因为PHP是服务器端脚本语言

你需要的是JavaScript,而不是PHP

var screenWidth = window.screen.width,
var screenHeight = window.screen.height;

然后,您可以通过Ajax(使用
XmlHttpRequest
)将其发送到服务器。

您使用文本字符串数据声明了两个字符串。从php的角度来看,这段代码没有错。如果您只想将两个变量设置为字符串值,那么这段代码也没有错,但它实际上没有实现任何功能。。。。也许你忘记了服务器端代码和客户端代码之间的区别,比如@CPUTerminator所说的可能的重复,它是一个字符串,其中的代码不会像这样执行。代码没有问题。关于代码应该做什么,您的验证有问题。你认为代码应该做什么?它实际上做什么?