As I asked here I would like to know how I could pass the data from a simple JS function to php, and log it there.
I found this answer and tried to follow it. This is my code right now (both in the same file)
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"> </script>
</head>
<body>
    <script>
        function getClientScreenResolution() {
            var screenResolutionW = screen.width; 
            var screenResolutionH = screen.height;
            console.log(screenResolutionW + ' ' + screenResolutionH)
            $.post("index.php", {screenResolutionW: screenResolutionW, screenResolutionH: screenResolutionH})
        }
    </script>
    <script type="text/javascript">
        getScreenResolution();
    </script>
</body>
</html>
<?php
$screenResolutionW  = $_POST['screenResolutionW'];
$screenResolutionH  = $_POST['screenResolutionH'];
if(isset($_POST['screenResolutionW'])) {
   $fh = fopen('log.txt', 'a');     
   fwrite($fh, 'Screen res: '."".$screenResolutionW .'x'."".$screenResolutionH 
."\r\n");
   fclose($fh);
}
?>
However, this does not work. I wouldn't know how to fix this, whenever I try to google this problem people use more advanced methods, that I wouldn't even know how to start with.
Edit: My PHP and HMTL are in the same file (index.php). Edit 2: Removed old code for clarity.
This results in these error messages:
Notice: Undefined index: screenResolutionW in index.php on line 153
Notice: Undefined index: screenResolutionH in index.php on line 154
 
    
 
     
     
    