📜  屏幕大小到 php 代码示例

📅  最后修改于: 2022-03-11 14:54:08.481000             🧑  作者: Mango

代码示例2
//Save in cookie to access with $_COOKIE["screenXYZ"];

//SetScreenResToCookie.php

  
//where u need the Screen res(only a example):
  
//header.php
//The function 

        var damn = setInterval(() => {
            var formData = {
                screenWidth: screen.width,
                screenHeight: screen.height
            };

            $.ajax({
                url: '" . $url ."/.../SetJScookie.php?" . time() ."',//This needs to be the URL on the domain u access the website from. ajax dont allow HTTPS
                type: 'POST',//because 'SetScreenResToCookie.php' use POST Array
                data: formData, //data in json format
                async: false, //enable or disable async (optional, but suggested as false if you need to populate data afterwards)
                success: function(response, textStatus, jqXHR) {
                    console.log(response);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        }, 1000);
    ";
}

function ReturnHeader($..., $...) {
  $Mobile = false;//If we dont wanne use Bootstrap or @media
  screenResToCookie();//set the cookie for us
  if (intval($_COOKIE["screenW"]) < 735) {
        $Mobile = true;
    }
  
  if ($Mobile) {
    //print header with mobile style(Dropdowns added or whatever)
  } else {
   //print header with Computer/Tablet style 
  }
}
?>