getting the full url including the query string after hash

user3034828 picture user3034828 · Nov 29, 2013 · Viewed 19.9k times · Source

How to get the full URL including the string parameter after hash tag? I try to echo

$url = $_SERVER['REQUEST_URI'];
echo $url;

the string after the hash tag wont read.

Answer

Konerak picture Konerak · Nov 29, 2013

Pekka's comment should be an answer. The string parameter after the hash tag is not sent to the server, it's for the browsers eyes only.

This means that serverside code (PHP, in your case) does not have this info. The clientside code (the browser, javascript, ...) does.

Ideally,

  • the part after the ? is info for the server. Put everything your server needs here
  • the part after the # is info for the client. Put everything your client needs here. It's called the Fragment Identifier (Thanks Tim).

Historically, the part after the # was most often used to have your browser quicky scroll to a defined anchor on the page. Nowadays, it is more often used to hold state information for the client.

You could have javascript send this info to the server, or perform different actions based on this info. AJAX is your friend.