Sending a JavaScript variable to a PHP function
Let's look at what the client can do as an alternative to setting a cookie:


Make an AJAX request that lets the server store the variable.
Add the variable name and value to the query string of every internal link and to every form submission (not just the next one).


I do not see any benefits of Solution 1, that justifies the extra HTTP request. Especially, you cannot circumvent the necessity for the user to have Cookies enabled, because the value must be stored close to the user and Drupal uses Cookies exclusively to determine the session (and thus the user).

Solution 2 allows for different values within the same session. If this is not one of your requirements, I consider this solution too much of a hassle.