How can I Pass a javascript variable value to PHP in Drupal 7
If you want to pass the value during loading page. You can do it by appending the JS value as query variable in path (e.g. http://www.example.com/new/page?demo=true) for requesting the next page. In PHP, you can use API drupal_get_query_parameters to read the data.

// retrieve data from www.example.com?data=value
$query = drupal_get_query_parameters();
$value = $query['data'];