2

When I have a URL such as this:

http://website.com/?var=foo

Then the $_GET array looks like this:

Array
(
    [var] => foo
)

But when I have a URL such as this:

http://website.com/#location?var=foo

Then the $_GET array is empty:

Array
(
)

Is this normal behavior? If so, is there a workaround for this scenario?

Nate
  • 24,336
  • 33
  • 121
  • 207

4 Answers4

5

This is correct way of url to get the $_GET values

http://website.com/?var=foo#location

The main problem is that the browser won't even send a request with a fragment part. The fragment part is resolved right there in the browser. So it's reachable through JavaScript.

You could parse a URL into bits, including the fragment part, using parse_url()

Source

Community
  • 1
  • 1
Yogesh Suthar
  • 30,136
  • 18
  • 69
  • 98
4

The value after the hash (including the hash) is never sent to the server, so when you do

http://website.com/#location?var=foo

the server never sees #location?var=foo

Reorder the string so the query string appears before the hash. ?var=foo#location

DevZer0
  • 13,316
  • 6
  • 25
  • 50
1

Put #location at last so your link became http://website.com/? var=foo#location

1

This is not the general format of url.

#location is a fragment, it should follow the query string

http://website.com/?var=foo#location
Vishnu Sureshkumar
  • 2,166
  • 5
  • 34
  • 51