I have some script like below but it does not work
<?php
$width = "<script>document.write(window.outerWidth);</script>";
$width2 = (int)$width;
echo $width2;
if ( $width2 < 800 ) { ?>
bad
<? } else { ?>
ok
<? } ?>
please help me ...
I have some script like below but it does not work
<?php
$width = "<script>document.write(window.outerWidth);</script>";
$width2 = (int)$width;
echo $width2;
if ( $width2 < 800 ) { ?>
bad
<? } else { ?>
ok
<? } ?>
please help me ...
You need JavaScript (taken from http://stackoverflow.com/questions/4180134/how-to-get-users-screen-resolution-with-php
and http://stackoverflow.com/questions/1504459/getting-the-screen-resolution-using-php
)
var screenWidth = window.screen.width,
screenHeight = window.screen.height;
You can then send it to the server via Ajax (with an XmlHttpRequest).
See also the MDC window.screen docs.
You mixed JavaScript and PHP.
<script>document.write(window.outerWidth);</script>
You cannot execute that JavaScript in PHP.
If you what to get browser width, you have to write a JavaScript and put it into browser to execute. The JavaScript should sent the size to server by AJAX/form post.