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

Patricia Arquette
Release: 2024-10-18 12:05:39
Original
243 people have browsed it

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!