Home > Article > Backend Development > How to Retrieve Complete URL, Including Query String and Anchor?
Retrieving the Complete URL with Query String and Anchor
Question:
When including a page into another, is there a way to retrieve the entire URL, including the anchor (the fragment after the #), that was used to access the current page?
Answer:
Unfortunately, retrieving the hash (the string containing the #) from the server is not possible because it is only retained within the browser and never transmitted to the server.
However, the $_SERVER['REQUEST_URI'] variable contains the remaining portion of the URL.
JavaScript Alternative:
If access to the hash is crucial, you can utilize the document.location.hash JavaScript property, which holds the hash contents. You can then embed it into a form or submit it to the server via an AJAX request.
The above is the detailed content of How to Retrieve Complete URL, Including Query String and Anchor?. For more information, please follow other related articles on the PHP Chinese website!