Look I do not understand why you want this information in PHP, but here is an example of how it could be done...
Create a file called detectScreen.php and include it on your main page:
<?php
@session_start();
if(isset($_GET['heigthJanela'])) {
$_SESSION['screenInfo'] = [
'heigthJanela' => $_GET['heigthJanela'],
'widthJanela' => $_GET['widthJanela'],
'heightTela' => $_GET['heightTela'],
'widthTela' => $_GET['widthTela']
];
echo '<script>
window.history.go(-1);
</script>';
die;
} else {
if(!isset($_SESSION['screenInfo'])) {
echo '<script>
window.location.href = "detectScreen.php?heigthJanela="+window.innerHeight+"&widthJanela="+window.innerWidth+"&heightTela="+screen.height+"&widthTela="+screen.width;
</script>';
die;
}
}
After this you can recover in your codes using the example below (test.php):
<?php include __DIR__ . '/detectScreen.php'; ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php echo $_SESSION['screenInfo']['heightTela']; ?>
</body>
</html>
You can’t communicate this before because PHP runs before Javascript. It will take at least 2 requests to get this information to the server.
– bfavaretto
@bfavaretto You’re right. Could post your comment as reply to I give as accepted?
– Rogério Dec
@Leo Caracciolo, both jquery and javascript run on the client side, the question is how to make PHP have this information on the first load, which is impossible, only if you do a redirect, hence it is already the second load.
– Rogério Dec
@Leo Caracciolo, I don’t think you understand yet, the question is how PHP can have this data in the first load, not jquery....
– Rogério Dec
Boy, how long do you live? That’s not possible with PHP and everyone is bald to know. I was just providing you an alternative that does not refresh the page. Good luck there for you.
– user60252
@Leo Caracciolo, sorry, it is that I thought you had not understood, but I appreciate your effort and your attention. Thank you.
– Rogério Dec
Relax!! It was nice that I developed another script!
– user60252