Home  >  Article  >  Backend Development  >  How to Retrieve Complete URL, Including Query String and Anchor?

How to Retrieve Complete URL, Including Query String and Anchor?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-18 12:05:39334browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn