Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP & determining client screen resolution

  • 22-04-2002 1:36pm
    #1
    Registered Users, Registered Users 2 Posts: 14,149 ✭✭✭✭


    Just wondering if anyone knows how to get PHP to read in a user's screen resolution

    much the same as the following javascript will do:

    function resolution()
    {
    yPoint = screen.height ;
    xPoint = screen.width ;
    }

    Or ... how to get the values from that javascript into php session variables or some such??


Comments

  • Registered Users, Registered Users 2 Posts: 5,741 ✭✭✭jd


    Originally posted by Lemming
    Just wondering if anyone knows how to get PHP to read in a user's screen resolution

    much the same as the following javascript will do:

    function resolution()
    {
    yPoint = screen.height ;
    xPoint = screen.width ;
    }

    Or ... how to get the values from that javascript into php session variables or some such??

    This may help -just lifted it from one of theose hit tracking sites
    <script language=javascript><!--
    s="";sc="";screencolors="";var xy = navigator.appVersion;xz = xy.substring(0,3);function
    write(){document.write("<a href='http://sitestatz.com/check.cgi?id=someuser' target='_top'>");
    document.write("<img height='25' width='25' border='0' alt='SiteStatz - free statistic tracker'",
    "src='http://sitestatz.com/statz.cgi?id=someuser&browser="+navigator.appName+"&version="+xz+"",
    "&ref="+escape(document.referrer)+"&screen="+s.height+"x"+s.width+"&colors="+sc+"'></a>");}
    //--></script><script language="javascript1.2"><!--
    s=screen;xy!="Netscape"?sc=s.colorDepth:sc=s.pixelDepth;
    //--></script><script language="javascript"><!--
    write();//--></script><noscript><a href="http://sitestatz.com/check.cgi?id=someuser">
    <img src="http://sitestatz.com/statz.cgi?id=someuser" border=0></a></noscript>
    


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    You could set a dummy index page that gets those values in javascript and sets them in a form and submits it. It should be pretty quick so the user shouldn't really notice.
    <form name="resolutionForm" action="setResolution.php" method="POST">
       <input type="hidden" name="width" />
       <input type="hidden" name="height" />
    </form>
    
    <script language="javascript">
    // set form values and submit the form
    // this isn't tested, you might need to change this but you get the idea
    document.resolutionForm.width.value = screen.width;
    document.resolutionForm.height.value = screen.height;
    document.resolutionForm.submit();
    </script>
    

    In setResolution.php just set those values into the session. You could put a piece of code in the top of ever page to check whether they exist or not in the session and if they don't, redirect the above page. You could also pass a referring page so it could go back to the page they're looking for.

    Hope this makes sense. :)


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Hi Lemming,

    Since no-one else has pointed it out, you can't do this in PHP, because PHP is server-side. So, as others have suggested, you need to tie in with a client-side language like JavaScript. Enygma's method is one example, although you don't actually need to use a form, you can just do it with a 'location' redirect:
    <script language="JavaScript">
     <!--
      w = screen.width;
      h = screen.height;
      top.location = '?w=' + w '&h=' + h;
     // -->
    </script>
    
    This will send the user back to the same page, but this time with the width and height in the QUERY_STRING. You can check for the existance of these vars in the PHP script, and, for example, set them in a cookie, or start a session. Alternatively, you could set a cookie on the first load with JavaScript.

    Also note that the dimensions you will get back will be the actual resolution, and won't cater for the chrome of the browser. (Or whether the window is normalised for that matter.)

    adam


Advertisement