You need to use the $_SERVER['REQUEST_URI'] variable.
I set up a quick test page
<?PHP echo $_SERVER['REQUEST_URI']; ?>
and called it with:
test.php?x=2&file=yes
which output:
/test.php?x=2&file=yes
So you'd wanna tack that into your code that gets the url up to that point.
Maybe something like:
<?PHP
echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
?>
Edit: I just double checked the code above, and that worked for me. It output:
scriptsamurai.com/test.php?x=2&file=yes