How to obtain anchor part of URL after # in php

While using LightBox mechanism in my project I got an URL http://nhs/search-panel.php#?patientid=2 I need to collect that patientid from this through GET mechanism, Is that possible in PHP?


Simply put: you can't! Browsers don't send the fragment (the part of the URL after the hashmark) in their requests to the server. You must rely on some client-side javascript: perhaps you can rewrite the url before using it.


Maybe everybody else is right and a simple $_GET is enough but if the # in your URL ( http://nhs/search-panel.php#?patientid=2 ) is supposed to be there you would have to do that with JavaScript (and Ajax e.g. JQuery) because everything after # is not included in the request as far as I know.


If you check your server logs, you should see that no browser actually transmits the #anchor part of the URL the request, so you can't pick it up on the server side.

If you need to know it, you'll need to write some Javascript to extract it from the document.location.href and send it to your server, either by turning it into a regular GET parameter and redirecting the user, or in the background with an XMLHttpRequest/AJAX.