3

I am asked to work with a service that changes my websites url to: http:://example.com/#/?id=9

I cannot seem to be able to get the id from such URL. $_GET is empty, $_SERVER['REQUEST_URI'] only contains /.

How am I supposed to get to the params?

Things I have tried:

Zend_Debug::dump($_GET); // outputs array(0)
echo $_SERVER['REQUEST_URI']; // outputs /
Zend_Debug::dump(parse_url($_SERVER['REQUEST_URI'])); // outputs array(["path"] => string(1) "/")

I am using Zend Framework but I doubt its something to do with it.

Thanks in advance.

Gordon
  • 312,688
  • 75
  • 539
  • 559
Iznogood
  • 12,447
  • 3
  • 26
  • 44
  • there is actually a couple questions asking this: http://stackoverflow.com/search?q=fragment+url+php. It's just somewhat non-obvious in your example because there is a slash after the fragment that makes it look as if the fragment was part of the path segments. – Gordon Sep 08 '11 at 15:36
  • @gordon to find these answers I would of had to know to look for fragment :) Thanks for pointing these out Ill check it out. – Iznogood Sep 08 '11 at 19:31

2 Answers2

3

You can't parse that with PHP, for the simple reason that as far as the URL concerns, anything beyond the # (hash) is not part of the URL, that part must be parsed with JavaScript or a similar client side language.

window.location.hash

Will return everything past the hash (including the # character)


In short: not possible in server, go with client. (maybe post an ajax call to a server with the GET data)

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • +1 I totally agree. For OP: sometimes when links are formatted like `top`, clicking on that link will send nothing to the server, but will stay on the same page instead. Thus using JavaScript seems to be the most reasonable way to do that. In case hash changes, you have [`onhashchange` event](https://developer.mozilla.org/en/DOM/window.onhashchange). – Tadeck Sep 08 '11 at 15:37
  • 1
    Yeah I am going to go with ajax not a big deal was hopping I could do it from php. Thanks! – Iznogood Sep 08 '11 at 15:59
1

Everything including and following the # is for the browser's interest only.

The server never even sees it.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055