It worked for me well:
- Create a hidden form on a HTML page.
- Create a Textbox or Textarea in that hidden form.
- After all of your code written in the script, store the final value of your variable in that textbox.
- First add a cookie jquery plugin.
- Then store that window width in a cookie variable.
- Access your cookie in PHP like $_COOKIE[‘variable name’].
How use external js file in PHP?
- Change CSS value by using PHP.
If you want to use a js variable in a php script you MUST pass it within a HTTP request. There are basically two ways: Submitting or reloading the page (as per Chris answer). Using AJAX, which is made exactly for communicating between a web page (js) and the server(php) without reloading/changing the page.
Why JS variables are not being set in PHP?
When php is processing this file (server side), the js variable is not set yet. Js variables are set client side, when php has already run and can’t interact anymore, unless you do another http request (for example with ajax).