How do I get the full URL in PHP, not just a part of it?

advertisements

This question already has an answer here:

  • Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)? 11 answers
  • Get the full URL in PHP 25 answers

This is my current URL structure http://wp.raddyx.in/consultant-dietitians/staff-single/#Fiona%20Brown

I am using echo $url=$_SERVER['REQUEST_URI'];

However it displays /consultant-dietitians/staff-single/ only, where I want to fetch the full URL.


Use $_SERVER["SERVER_NAME"] to get the host name wp.raddyx.in

Use $_SERVER["HTTPS"] to check for http vs https.

You might need $_SERVER["SERVER_PORT"] too and some other misc things that can appear in a URL (like PHP_AUTH_USER)

You can not get the hash part of the URL (#Fiona%20Brown) since hashes are client-side only. They are not sent to the server.

Relevant manual page: http://php.net/manual/en/reserved.variables.server.php