As you have written in your question you have to check the correct width on the front-end side. You can use it jQuery or pure JS.
If you want to set some PHP variable and pass it to the PHP script then you have to use AJAX.
And again.. You can use it as a plain JS (XMLHttpRequest
object) or ajax
method from jQuery, like that:
JS code:
var variableForPHP = <?php echo 'some_value' ?>;
$.ajax({
url: 'script.php',
method: 'post',
dataType: 'json',
data: {phpVariable: variableForPHP},
success: function (respondFromPHP) {
// do something after AJAX call
console.log('respond from PHP: ' + respondFromPHP);
}
});
PHP code:
<?php
$variableFromAjax = $_POST['phpVariable'];
// do something
var_dump($variableFromAjax);
$respondToAjax = 'thanks for variable: '. $variableFromAjax;
echo json_encode($respondToAjax);
?>