why this print size on screen but do not save to file?
Can somebody help me!
Thanks

<?
$mw = "<script> document.write(window.innerWidth); </script>";
echo $mw;
$mh = '<script> document.write(window.innerHeight); </script>';
echo $mh;
 $q=$mw*2;   
echo $q; //$q give 0 $n="hit.txt"; $fo=fopen($n,"a"); fputs($fo,$mw."\r\n"); fputs($fo,$mh."\r\n"); fclose($fo); ?>

    Welcome to PHPBuilder! When posting PHP code, please use the board's [noparse]

    ..

    [/noparse] bbcode tags as they make your code much easier to read and analyze.

    As for your issue... do you have display_errors set to On and error_reporting set to E_ALL? Also, try using something like [man]var_dump/man to check the return value of the [man]fopen/man call - make sure it isn't boolean FALSE (indicating an error has occurred).

      It looks like you're getting confused about Javascript and PHP and where each gets executed. What will actually happen with your code is that those <script> tags will be added to your hit.txt file (assuming it's got the right permissions, which could be another issue which may be why the file isn't saved)

      PHP is run on the server, and Javascript is run in your browser, but you're attempting to mix them here in a way that won't work. If you want to get the dimensions of the screen added to a text file, then you need to do that with some sort of post back from the browser to the server. This is usually done with a single pixel image request (that actually points to a PHP script) with some extra info tagged onto the end of it:

      <script type="text/javascript">
      w = window.innerWidth;  // note these two variables won't work in all browsers
      h = window.innerHeight;  // note these two variables won't work in all browsers
      imgObj = new Image();
      imgObj.src = "http://yourdomain/hit_count.php?w=" + w + "&h=" + h;
      </script>
      

      As noted above, the way you're attempting to get the width and height isn't compatible with all browsers, you should flesh that part out a bit, as IE, Firefox, etc have subtle differences in the way they do things like this.

        Write a Reply...