Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 289779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:56:16+00:00 2026-05-12T05:56:16+00:00

I almost sure that PHP can’t detect the View port size of a browser

  • 0

I almost sure that PHP can’t detect the View port size of a browser right?

But since that, can someone teach me how can i do it with Javascript and then gather that size from a Javascript variable to a variable in PHP?

Regards

PS: Sorry if there is another post with the same question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:56:17+00:00Added an answer on May 12, 2026 at 5:56 am

    To get the viewport size, you must use Javascript, yes.
    For examples of code doing that (not always easy, there are differences between browsers), you can take a look at how JS Frameworks/Libraries determine that size (for instance, in prototype.js, there is a getDimensions function that does what you want) ; google will get you lots of results about that too (this one is an example of those results)

    Then, you must send that size to PHP. For that, two solutions :

    • One is to use an Ajax request (sending the width and height as parameters)
    • The other is to dynamically build an <img> tag, with an URL pointing to the PHP script, like 'http://.../size.php?w=WIDTH&h=HEIGHT'
      • many statistic software (things like xiti / google analytics — not sure if those ones do ^^ ) use that kind of method.

    In the second case, the JS code could look like this :

    <script type="text/javascript">
        var width = 100;
        var height = 80;
        var tag = document.createElement('img'); // Create the tag
        tag.src = 'http://tests/temp/viewport/size.php?';
        tag.src += 'w=' + width; // Pass the size
        tag.src += '&h=' + height;
        document.body.appendChild(tag); // Insert the tag into the page
    </script>
    

    And then, in size.php, you use $_GET[‘w’] and $_GET[‘h’].
    Note : you will probably have to return some valid image data from size.php, to not get a “red cross” picture (a transparent gif, 1×1 in size, for instance, will do the trick)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone write a PHP script that reproduces the functionality of this linux shell
When you search in Google (i'm almost sure that Altavista did the same thing)
So the question is in title. I almost sure that the answer is NO,
The doc is mentioning an CGBitmapContextGetBitsPerPixel(). I am almost sure that I would just
I almost have it working, but even then not sure if it's properly implemented.
Although I am almost sure this has been covered, I can't seem to find
I'm almost 100% sure I have ready every post on the internet that contains
I'm almost sure this question has been asked before, but for the love of
Probably someone has already asked this question but I'm not sure what I'm looking
Almost every Python web framework has a simple server that runs a wsgi application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.