I think your getting a little confused between server side and client side code. The PHP code is executed on the server, and the Javascript code which you generate with PHP is then executed on the client. You can't store the result of the Javascript code within a PHP variable since PHP is no longer involved at that point.
You can get the current request, along with a bunch of other useful stuff with the $_SERVER array, why bother with Javascript at all?.