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

后端 未结 2 838
谎友^
谎友^ 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:13

    How about having your document ready AJAX request send to a separate PHP document, then include that in the head on page load. That way, you can have whatever specific HTML you want loaded put straight into the body when ready.

    For example:

    
    
    
    
    

    And then your body.php file would look something like:

    If you then didn't want that JS function to run every page load, just encase the whole thing in a

    I'm not 100% sure what you were intending to do with the dimensions once you have them, so I apologise if my answer is a little vague, but by doing it this way the page only sets the saved dimensions on the first visit this browsing session, and it doesn't have to redirect, so I hope it's at least a little helpful :)

提交回复
热议问题