Get user's screen&viewport dimensions in php on first load

后端 未结 2 802
谎友^
谎友^ 2021-01-03 03:01

I want to get in PHP the height/width of both the screen and the viewport when a user visits a page.

I\'ve tried different ways but they all cause other problems.

2条回答
  •  一生所求
    2021-01-03 03:24

    I think it's better to ask yourself: What do you want to do with the width and height? And look if there are other ways to accomplish that goal. You cannot get the user his screen width and height using PHP because it runs server-side.

    So this data is never available on the first load.

    You could submit the data using AJAX and then make the changes to the page using JavaScript. Then the next page reload the data is, when stored, server-sided available.

提交回复
热议问题