Two $_GET in one query string?


What would happen if I ever end up with a utl like this?

I am asking because I am making a redirect appending this bit to the incoming url: ?someothervar=test

My question is obviously: what happens if the incoming url already has a querystring (such as ?var1=blah&var2=ok) and I append to it ?someothervar=test ? Should I test for every incoming request to check if a querystring already exists?



See print_r($_GET); to see what it gives you:


It will return you:

Array ( [var1] => blah [var2] => ok?someothervar=test )

Instead you should do something like this:

$url = ''; // your existing url

// now you can append it like this by checking if ? exists:
$url .= (strpos($url, '?') === false) ? '?' : '&';
$url .= 'someothervar=test';
echo $url;

Worked like a charm… :tup:

I’m just having a bit of a problem with fragment identifiers. How should I format an url with a fragment identifier and a querystring? doesn’t seem to work nicely.

See the function parse_url and some examples there.

Hello, read it and the examples, I’m still not sure how the url should be formed. Parsing it is only a secondary concern. I just want the browser to recognize the fragment identifier AND use the querystring with PHP.


The fragment identifier always comes last


It seems that the fragment identifier appears in $_GET[‘foo’] though.

$_GET[‘foo’] == bar#somefragment

Is there a solution to this?

I didn’t get that when I tried it (fragment coming through in GET value).
What does your link href look like in the HTML source (i.e. how is PHP rendering the URL)?

Do you mean the Octet (or is it Octothorpe?) is appearing in your URLs and you’d like to remove them?