1

I want to echo exact url : http://domain.com/mystuff.html#123456

but it only print http://domain.com/mystuff.html how to include the #123456 ? so become http://domain.com/mystuff.html#123456

my code so far

$urladdress =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
alyasabrina
  • 2,977
  • 3
  • 16
  • 7

3 Answers3

4

You cannot. The fragment identifier is handled entirely client side so the browser will not send it to the server.

(The nearest you could come would be to (after the page has loaded) use JavaScript to sent it to the server in another request.)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

you cannot get it using php, you can get it done by javascritp. use this test script to check your result.

<script>
alert(document.URL);

    var urlDetail = document.URL;//you can use this variable to print in your web page.
</script>
sudhakar
  • 582
  • 1
  • 3
  • 13
-1

Found the answer:

<a href="'.$urladdress.'#'.parse_url("http://domain.com?page.html#123456",PHP_URL_FRAGMENT).'">text</a>
alyasabrina
  • 2,977
  • 3
  • 16
  • 7