1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get Screen resolution of User in PHP

Discussion in 'PHP' started by coderzone, Dec 23, 2007.

  1. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    Is there any way to know the User Screen Resolution in PHP.

    I am not sure if it can be done also,
     
  2. onlyani

    onlyani New Member

    Joined:
    Dec 23, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    PlanetPHP
    The pages you make (as php developer) could
    use client-side javascript to detect the local
    screen resolution. Then, theoretically, you could
    send an Ajax message back to the server, to set
    a session variable, so all subsequent requests
    could be either dynamically generated, with differing
    image sizes, or you could, maybe, use url-rewriting
    to redirect to the right static html (with differing
    image sizes).

    But that's got a hidden catch22. Because the 37% of
    all users who still use 800x600 resolution probably won't
    have browsers that can deal with Ajax requests.

    Has anybody ever figured out how to optimize image
    sizes for different screen resolutions?
    :nonod:
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    The best possible solution is

    <script language="javascript">
    if (window.location.search == "") {
    window.location.href = window.location + "?width=" + screen.width + "&height=" + screen.height;
    }
    </script>

    Then create a file called screen.php and use this:

    <?php
    $width = $_get['width'];
    $height = $_get['height'];

    echo "You are using a $width x $height screen resolution";
    // And set them into cookies as well.
    ?>

    You can also look into http://www.webmasterworld.com/forum88/4700.htm
     

Share This Page