For a variety of reasons I need my server-side PHP code to be aware of the client's window width. I've tried the following PHP snippet:
echo '
<html>
<head>
<title>Yadda yadda</title>
<!-- Etc... -->
<script type="text/javascript" src="javascript/jquery-1.10.1.min.js">
</script>
<script>
document.cookie="resH="+$(window).width()+"; path=/";
</script>
</head>
<body>
';
if (isset ($_COOKIE ['resH'])) {
// do stuff
} else
// do other stuff
}
The problem is that when I check for the cookie, the browser has not yet had the time to set it and notify the server of this fact. In other words, this is sufficiently asynchronous to mess up my timing, and the cookie check either fails or uses the cookies set on the previous page load.
Is there a way to address this, or is my only option to abandon this approach in favor of something completely different?