I know $_SERVER[‘REQUEST_URI’] works in getting the current page’s url, but it leaves out the #post at the end of the url. I like to use the #blah at the end to make the page scroll to a certain point. Example:
index.php#answer
using $_SERVER[‘REQUEST_URI’] just returns:
index.php
How can I make it read the #answer at the end as well?
URL hashes are never sent to the server. So it’s impossible to retrieve it using PHP or any other server-side language.
To achieve the scrolling, give the element you want to scroll to
id="answer"– then the browser will jump to it automatically. In case you want to perform smooth scrolling using JavaScript, you can access the hash vialocation.hash– there are some nice jQuery plugins available which will take care of scrolling smoothly to a specified element.