Passing javascript variable to php file

You could use cookies – set in JS, and read from PHP.
Another way can be using an AJAX request to get the variable value.