18

Possible Duplicate:
Getting the screen resolution using PHP

well the question is self explanatory

where i want to reach is

$width = ; //user screen width in here

F1! F1!

Community
  • 1
  • 1
Moon
  • 17,794
  • 55
  • 130
  • 193
  • Although you cannot strictly detect the resolution of the User's environment, but based on the User Agent string, you can guess with reasonable accuracy the class (mobile/tablet/desktop) of the device used. Check out http://mobiledetect.net/ . – bds May 23 '17 at 19:00

4 Answers4

40

You need JavaScript, not 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.

Matt Ball
  • 332,322
  • 92
  • 617
  • 683
9

You can't, not in php. PHP is strictly server-side.

Femaref
  • 58,195
  • 7
  • 126
  • 170
  • 4
    geez.... why do i forget this fact.... – Moon Nov 15 '10 at 00:37
  • 1
    HI, I understand. But info like browser type,vendor and prefered languages etc. which we can access from `$_SERVER` variable. For eg: `$_SERVER['HTTP_ACCEPT_LANGUAGE']` like this for language. Even though it is server side language and execution, still we can get info like this from client. I wonder the screen size also should be provided, but i know it is not in current generation may be in future they can add.@Femaref – sun Feb 21 '14 at 09:25
  • Those are http headers. Http is used to access webpages, but that's not the only thing it does. It's a standard for data transmission, as such, things like screen space (which is something of concern after the data arrives at the client is cosmetic) does not have a place in the http standard. – Femaref Feb 23 '14 at 12:12
  • What are you talking about? You can't get the clients resolution in php, as php isn't executed on the client. – Femaref Nov 13 '14 at 12:41
5

you can't get it server-side, you have to get it client-side with javascript with innerWidth. you can pass it to the server-side with AJAX if you need to.

jcomeau_ictx
  • 35,098
  • 6
  • 89
  • 99
2

You can use JavaScript. Get the user's screen, send it to the server and get it by php.

Pithikos
  • 14,773
  • 14
  • 98
  • 115
frend
  • 21
  • 1