Retrieving the full URL, including the query string after the hash

How to get full URL including string parameter after hash tag ? I'm trying to echo

 $url = $_SERVER['REQUEST_URI']; echo $url; 

the line after hash tag not readable.

+2
url php hashtag
source share
2 answers

Pekka's comment should be the answer. The string parameter after the hash tag is not sent to the server , it is only for the eyes of the browser.

This means that the server code (PHP, in your case) does not have this information. Client code (browser, javascript, ...).

Perfectly,

  • part after? for the server . Put all your server here
  • the part after # is customer information . Put all your customer needs here. He called the Fragment Identifier (Thanks Tim ).

Historically, the part after # was most often used to quickly jump your browser to a specific anchor on the page. Currently, it is more often used to store status information for a client.

You could javascript send this information to the server or perform various actions based on this information. AJAX is your friend.

+8
source share

A hash (string, including #) is never passed to the server; this is an exclusively behavioral property of the browser. However, the variable $_SERVER['REQUEST_URI'] will contain the rest.

If you really need to know what a hash is, you will need to use the JavaScript document.location.hash property, which contains the contents of the hash (you could then paste it into the form or send it to the server form with an ajax request). You can pass the full URL, including the anchor (the part after #), using the Javascript onload function , which sends the URL to the ajax endpoint.

You can also look here Get the entire URL, including the query string and binding

+1
source share

All Articles