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?

3
  • Why isn't the hash at last? Commented Jul 17, 2013 at 4:01
  • I would imagine this is normal behaviour, the hash needs to be after the query. Commented Jul 17, 2013 at 4:02
  • possible duplicate of Php to get value of hashtag from URL Commented Jul 17, 2013 at 4:03

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

5 Comments

He is asking how to get values after the hash, not how it should be, He's link is perfectly fine.
@MihaiIorga: His link isn't perfectly fine, if he wants some GET parameters to appear.
No, he asked if the behavior is normal, witch is.
@MihaiIorga i know computers are very literal when interpreting things, but humans shouldn't be.
@chris I don't think anyone who answered even read the question, all told him that is not a good link but he asked if the behavior is normal and what workarounds he has.
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

Comments

1

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.