Hi,

I would like to get the screen width and height of the client to store in a MySQL DB.
In JavaScript, screen.width and screen.height give me what I want but how can I do to get these values in a PHP piece of code ?
I should do it by asking the PHP page with these values as parameters but I find this way not very nice.

Thanks for helping.

Vincent CALLUT.

    6 months later

    I have the same problem. I was trying to program a serious counter, which would identify the screen resolution and write it to MySql database, but I have failed so far... does anyone has any kind of idea how to do that?

    thank you!

      Okay... that's how it could be done:

      <?
      echo("Screen resolution of the client:<br><br>");
      ?>
      <script language="JavaScript">
      if (screen.width=1280) write("<? $screenwidth ='1280' ?>");
      if (screen.height=1024) write("<? $screenheight ='1024' ?>");
      </script>
      <?
      $resolution = $screenwidth."*".$screenheight;
      echo($resolution);
      ?>

      as you have noticed, this only works with resolution 1280*1024 so far, but if you do the rest of the work by yourself, it's full...

      have nice day(actually it's night in here where I am =) )!

        2 months later

        Well, I don't think this code can work well.
        The javascript function write() does not send its argument to the webserver.

        It may have worked for you because in your javascript code, there is some php code :
        write("<? $screenwidth ='1280' ?>");
        The php interpreter will affect the $screenwidth variable to '1280' and will return an empty string, which will be used as argument for the write function. Open the HTML source generated in your browser and you'll see the line write(""); instead of write("<? $screenwidth ='1280' ?>");

        There's a post from Troy Settle dated 10/10/00 describing a solution.

          2 months later

          Hello,

          The way I grab the clients screen resolution is to have a main page that grabs visitor info and then forwards the visitor to the main page. An example of this would be to have default.php be your main page and then use a meta refresh tag to forward them to your main page such as index.php. Inside default.php you can use javascript to set a cookie(assuming the client has cookie enabled) and then in index.php you could use php to retrive the cookie. If the visitor doesn't have cookies enabled then you could use javascript in your default.php page to append the screen resolution to the url you're redirecting to. Here are examples of both:

          Example 1(Assuming user has cookies enabled):

          --- default.php ---

          <HEAD>
          <TITLE></TITLE>
          <script language="javascript">
          document.cookie = "javaInfo=" + screen.width + "x" + screen.height;
          </script>
          <META HTTP-EQUIV="Refresh" CONTENT="0;URL=index.php">
          </HEAD>
          <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
          </BODY>

          Example 2(Assuming user has cookies disabled):

          --- default.php ---

          <HEAD>
          <TITLE></TITLE>
          <script language="javascript">
          document.write('<META HTTP-EQUIV="Refresh" CONTENT="0;URL=index.php?');
          document.write('javaInfo=' + screen.width + 'x' + screen.height + '">');
          </script>
          <META HTTP-EQUIV="Refresh" CONTENT="0;URL=index.php?p=1">
          </HEAD>
          <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
          </BODY>

          In either case all you would have to do to access the info would be the following:

          --- index.php ---

          $temp_array = explode("x", $javaInfo);
          $xres = $temp_array[0];
          $yres = $temp_array[1];

          Now you're done. If you used the cookie example you can access the resolution information from any page, since the cookie will not expire till the user closes the browser. However if you used the second method you will only be able to access the resolution from index.php if they visitor has just been redirected from your default.php page.

          I hope these examples help you and anyone else out, looking for a way to get screen resolution.

            Write a Reply...