How to get fragment ID from URL in PHP? [duplicate

2019-03-02 07:58发布

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!

标签: php joomla
2条回答
手持菜刀,她持情操
2楼-- · 2019-03-02 08:22

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 and window.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 use parse_url("URL HERE",PHP_URL_FRAGMENT) function to get the fragment hash.

查看更多
趁早两清
3楼-- · 2019-03-02 08:45

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.

查看更多
登录 后发表回答