javascript - Need to set a cookie client-side and immediately use it server-side -


for variety of reasons need server-side php code aware of client's window width. i've tried 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'])) {     // stuff   } else     // other stuff } 

the problem when check cookie, browser has not yet had time set , notify server of fact. in other words, sufficiently asynchronous mess timing, , cookie check either fails or uses cookies set on previous page load.

is there way address this, or option abandon approach in favor of different?


Comments