解析URL查询中的URL查询

At some point in my application the user is sended to this URL:

https://mysite.com/bframe/auth?next=/bframe?foo=bar&foo2=bar2

As you can see, the next parameter in the URL actually contains a new url query, that have foo and foo2 as parameters. To parse the next parameter in Zend2 im using just:

$next = $this->getController()->getRequest()->getQuery('next', null);

But that gives me back just the first parameter /bframe?foo=bar trimming &foo2=bar2, that kinda makes sense since getQuery sees the first question mark as the query? I dont get it quite well, the thing is, how can I retrieve the complete value of next?

urlencode() your "next" content

$url = 'https://mysite.com/bframe/auth?next=' . urlencode('/bframe?foo=bar&foo2=bar2');

Your URL should then look like:

https://mysite.com/bframe/auth?next=%2Fbframe%3Ffoo%3Dbar%26foo2%3Dbar2

And you will note there are no longer any ambiguous ? and & characters


As I'm not sure how you're using $next next in your code, the concept is to url encode any data you plan to insert into a further url query string structures