Two $_GET in one query string?

Hello,

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


http://somesite.com/?var1=blah&var2=ok?someothervar=test

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?

Cheers.

:slight_smile:

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


print_r($_GET);

It will return you:

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

Instead you should do something like this:


$url = 'http://somesite.com/?var1=blah&var2=ok'; // 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?

http://somesite.com/#message?var1=blah&var2=ok?someothervar=test 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.

:slight_smile:

The fragment identifier always comes last


http://www.example.com/?bla=bla&foo=bar#somefragment

Thanks,

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?