tags:

views:

154

answers:

4

When using the $_GET[] in php, it searches for a variable e.g ?id=value

Is there a way to call the #value instead?

+8  A: 

No, because the hash part of the url is client-side only and is not sent to the server.

When you enter an URL such as http://server.com/dir/file.php?a=1#something in your browser's URL textbox, the browser opens a connection to the server.com and then issues a HTTP command GET /dir/file.php?a=1 HTTP/1.1. This is the only data sent to the server. Hence, the server never gets the #something part, and this means there is no script on server side you could write to read that value.

Similar question explained here: http://stackoverflow.com/questions/317760/how-to-get-url-hash-from-server-side

naivists
Thanks for your prompt answer naivists
Andy
Frank Farmer
@naivist Interesting. I was convinced having seen the fragment in an URL on the serverside before, but you are right, thus I deleted my answer. Now I only need to find the RFC that says why it is like this. After all, it's a valid URI component.
Gordon
I think, this is it: http://tools.ietf.org/html/rfc2396 - Section 4.1
Gordon
Frank Farmer, one of reasons why this may be done is - to let the client stay on the same page without refresh. That is, if you add a link in your page to, say, `samepage.htm#something`, and click that link, your page is not refreshed. However, you can catch that event in javascript, and, using AJAX, call for some more data from the server.
naivists
A: 

Yeah there is a way. I think what you want to do is:

$arValues = array_values($_GET);
// whatever else you want to do with the values
Daniel
He wants to get the URL fragment. What he means by ?= is the regular params, e.g. foo=bar. But he is looking for the value in the URL after #.
Gordon
correct. I have opted to use normal ?=variable
Andy
A: 

I've been able to work around it by getting the fragment via javascript and sending an ajax request with the fragment as the $_GET contents.

gabrielk
A: 

Without knowing your whole case, I may be off track, but there is the possibility of sending the #something to the server via a simple GET type of xmlhttprequest.

luminarious