0

Let's say the current URL is www.example.com/example.php?var=test#1

$_SERVER['QUERY_STRING']; 

should return

var=test#1

but it just returns

test

It happens every time a "#" symbol is inserted in the URL.

How can i fix it ? I really need to get the current query string but i CAN'T use $_GET (please don't ask why it would be really too long to explain). I also have no control over the URL and i can't control the url string or encode it before it reach my server.

Edit: same problem with $_SERVER['REQUEST_URI'];

Anar Choi
  • 201
  • 2
  • 3
  • 9
  • 1
    Everything after the `#` pound symbol is the fragment identifier, and always remains client-side. It's never part of the HTTP request path. – mario Jul 04 '13 at 00:42
  • It should return `var=test`. The part after (and including the `#`) is called the hash and it is not sent to the server. So you will never be able to access it from `$_SERVER['QUERY_STRING']`. – Bailey Parker Jul 04 '13 at 00:42
  • I'm not seeing that behaviour here.. Are there any server redirects going on? – msturdy Jul 04 '13 at 00:44
  • I really need to get the exact query string. I have no control over it and it can contain any characters. If i use $_GET then characters like "? , & , +" will break the result and if i use $_SERVER['QUERY_STRING'] then symbols like "#" or "|" will also create a bug...... So there is no solution for me ? – Anar Choi Jul 04 '13 at 01:29

2 Answers2

1

If you do actually need to know what the hash is, you will have to use the document.location.hash JavaScript property, which contains the contents of the hash....other than that, theres no way to get the hash with php as it is not passed to the sever

Kylie
  • 11,421
  • 11
  • 47
  • 78
  • +1. Not sure who down voted this, but you're right. Hashes are client-side only. – Rob W Jul 04 '13 at 00:47
  • It is not an hash, just an URL with a # ... I need to send the "hash" value to PHP – Anar Choi Jul 04 '13 at 03:04
  • It is a hash, thats what # is. And you cant send it to PHP....anything after # doesn't make it to the server....I already said that – Kylie Jul 04 '13 at 16:44
0

The # symbol in a URL represents a link to a named anchor, and isn't part of a query string. To be reliably passed as part of your query data it should be encoded to %23.