Если я правильно понял, ваш вопрос: когда пользователь заходит на вашу страницу (например, попробуйте. php), как передать переменную javascript (например, screen.width screen.height) в раздел PHP, чтобы вы можно сделать как переменную PHP.
Вот рабочее решение.
try. php
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="" method="POST" name="myForm" id="myForm">
<input type="hidden" id="screenWidth" name="screenWidth">
<input type="hidden" id="screenHeight" name="screenHeight">
</form>
<script type="text/javascript">
document.getElementById("screenWidth").value = screen.width;
document.getElementById("screenHeight").value = screen.height;
function autoSubmit ()
{
let form = document.getElementById("myForm");
form.submit();
}
window.onload = autoSubmit;
</script>
</body>
</html>
<?php
if($_SERVER["REQUEST_METHOD"] === 'POST')
{
if(!empty($_POST["screenWidth"]))
{
$screenWidth = $_POST["screenWidth"];
echo $screenWidth; // see if it gets the screen.width
}
if(!empty($_POST["screenHeight"]))
{
$screenHeight = $_POST["screenHeight"];
echo $screenHeight; // see if it gets the screen.height
}
}
?>
Это в основном манипулирование DOM и изменение значение входного значения должно быть screen.width и screen.height, а затем автоматически отправлять форму при загрузке окна.
Если сервер получил входные данные метода HTTP POST, тогда он проверяет имя POST входы и сохранить его в каждой PHP переменных.