This question already has an answer here:
I'm using
location.hash = $(this).attr("id");
to append id into url bar immediately without reloading. the outcome is : http://example.net/index.php/abc#id
then I echo
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
the output I got was : http://example.net/index.php/abc
How can I get the #id (known as fragment id ) in PHP so that it can be used as PHP variable ?
Thank you!
You can not directly send the fragment part from client to the PHP server side. But the fragment id can be accessed through javascript and you can send it to server as a GET parameter. Use
window.location
to get the full url including fragment part andwindow.location.hash
to get just the fragment part in javascript. In case you send the full url (including fragment hash) to the PHP server, you can useparse_url("URL HERE",PHP_URL_FRAGMENT)
function to get the fragment hash.The webserver don't receive the hash fragment, it's client side only. So you cannot get it with PHP or any other server side language. You can hack around by fetching that hash via javascript and sending it via a GET parameter to the server side script but i don't recommend this.