-1

Why does $_GET deliver different results if I call an URL with an anchor compared to without?

example:

https://www.myurl.com/#anchor?param1=x&param2=y

if I read the GET params, REQUEST, $_SERVER['QUERY_STRING'], parse_url($url, PHP_URL_QUERY) all are emtpy

but with

https://www.myurl.com/?param1=x&param2=y

everything works as expected.

Can anyone explain me this please?

Canelo Digital
  • 340
  • 2
  • 10
  • 3
    `#` denotes an URL fragment, fragments aren't passed to the server so you've just snipped your entire querystring - it would work like `https://www.myurl.com/?param1=x&param2=y#anchor` however – CD001 Feb 06 '19 at 16:28
  • 3
    Because `#` indicates the beginning of URL fragment part of the string, which comes after GET params and includes everything after the #. – Jonnix Feb 06 '19 at 16:28
  • 1
    Put anchor at the end: `https://www.myurl.com/?param1=x&param2=y#anchor` – marekful Feb 06 '19 at 16:28
  • thanks to all, and I do not consider it a duplicate as I was asking about the "disappearing" query parameters, not the availability of the anchor on server side. – Canelo Digital Feb 06 '19 at 17:02

2 Answers2

2

Basically the hash component of the page URL (the part following the # sign) is processed by the browser only - the browser never passes it to the server. This sadly is part of the HTML standard and is the same whether or not you are using IE or any other browser (and for that matter PHP or any other server side technology).

Check the explanation from here.

bhalu007
  • 131
  • 1
  • 10
1

Anchors go at the end, hence the name. :)

https://www.myurl.com/?param1=x&param2=y#anchor
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98