how to get screen size with php code example
Example 1: Getting Screen Resolution PHP
$(function() {
$.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
if(json.outcome == 'success') {
} else {
alert('Unable to let PHP know what the screen resolution is!');
}
},'json');
});
<?php
if(isset($_POST['width']) && isset($_POST['height'])) {
$_SESSION['screen_width'] = $_POST['width'];
$_SESSION['screen_height'] = $_POST['height'];
echo json_encode(array('outcome'=>'success'));
} else {
echo json_encode(array('outcome'=>'error','error'=>"Couldn't save dimension info"));
}
?>
Example 2: device width js
window.screen.availWidth
Example 3: php get screen width
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = "Total Width: " + screen.width + "px";
document.getElementById("demo").innerHTML = x;
}
</script>