0

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 ...

Abdul Basith
  • 1
  • 1
  • 4
  • http://stackoverflow.com/questions/1504459/getting-the-screen-resolution-using-php – Raúl Monge Dec 19 '14 at 08:45
  • php is run on the server, so the screen width can't possibily be available to it, you'd need javascript, or if your doing css based on screen size, media queries – atmd Dec 19 '14 at 09:17

2 Answers2

0

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.

Nepal12
  • 583
  • 1
  • 11
  • 28
0

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.

user4344980
  • 303
  • 1
  • 2
  • 6