what wrong with this php code - Get Screen resolution of User in PHP

Discussion in 'Programming' started by ironmankho, Sep 23, 2009.

  1. #1
    originally copy from :

    http://www.go4expert.com/forums/showthread.php?t=7979

    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.
    ?> 
    PHP:
    i have little knowledge about php . can any body explain this code . i already copy paste this code but get error like

    but in browser window :
    You are using a x screen resolution

    in URL bar :
    http://localhost/scr/screen.php?width=1280&height=1024

    actually i want Screen resolution of User in PHP.is there any simple method for this (php)

    thanks
     
    Last edited: Sep 23, 2009
    ironmankho, Sep 23, 2009 IP
  2. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #2
    I think this should work now, but I haven't tested it.

    
    //I'm assuming this is a separate page, so i changed a little of it.
    <html>
    <head>
    <script language="javascript">
    window.location = "screen.php?width=" + screen.width + "&height=" + screen.height;
    }
    </script>
    </head>
    </html>
    
    Code (markup):
    
    <?php
    session_start();
    $width = $_get['width'];
    $height = $_get['height'];
    
    setcookie('width',$width);
    setcookie('height',$height);
    
    echo "You are using a $width x $height screen resolution";
    // And set them into cookies as well (done with setcookie())
    ?>
    
    Code (markup):
    viola!
     
    tguillea, Sep 23, 2009 IP
  3. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Last edited: Sep 23, 2009
    ironmankho, Sep 23, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Should probably be $_GET instead of $_get.
     
    premiumscripts, Sep 24, 2009 IP