-1

Please help me out, if i have a URL like this

http://www.example.com/dashboard.php#settings

How do i get it in full cause. when I use:

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

I get http://www.example.com/dashboard.php it excludes the # and the text after it, how do I go about getting everything in full like this http://www.example.com/dashboard.php#settings.

Teemu
  • 22,918
  • 7
  • 53
  • 106
Lio
  • 11
  • 3
  • 7
    You can't get it with PHP, it's never sent to the server. You'll have hack some javascript on the frontend to send it. – Andrei Sep 29 '17 at 08:37
  • @Teemu please help me out stuck on all the solutions i have seen online no hack to this. – Lio Sep 29 '17 at 08:43
  • @Calimero Thank you looking at it now. – Lio Sep 29 '17 at 08:44
  • @Lio where have you looked, there are plenty of sources you can use JavaScript `window.location.hash` to get the fragment and send it to PHP or whatever you need. – xander Sep 29 '17 at 08:45
  • @xander looked at a lot of post on stack and sitepoint currently looking at this https://stackoverflow.com/questions/967649/get-entire-url-including-query-string-and-anchor but not making so much sense please could you elaborate with an example on your answer – Lio Sep 29 '17 at 08:49
  • You will need to show the code where your Link gets triggered for that. And then explain what you have tried with your new information you got. – rndus2r Sep 29 '17 at 08:56

1 Answers1

0

Url fragments are never sent to server side you have to use get or post and send the value to server side in order to perform some actions or you can use your hashtag but also some client-side javascript to send the hashtag value as post or get parameter to the server side.

parse_url() can parse the URL with fragments but it is useless in this case since the fragment is never sent to the server side.

if(window.location.hash) {
  // fragment exists send request to server side as get or post
} else {
  // fragment does't exists
}