Framework: Request()->query strips away query parameters if they are part of the query parameter

Created on 23 Oct 2018  Â·  2Comments  Â·  Source: laravel/framework

  • Laravel Version: 5.6
  • PHP Version: 7.2
  • Database Driver & Version: MySQL 5.7

Description:

I have a URL passed in a "next" variable in request query. The URL has its own query parameters. However, request()->query('next') strips away the query parameters starting with '&'

FULL URL: http://example.com/my-page?next=http://example.com/some-other-page?id=10&cat=123

But request()->query(‘next’) = http://example.com/some-other-page?id=10 which is wrong
as it has stripped away the remaining query parameters.

Most helpful comment

Laravel can't know whether &cat=123 belongs to /my-page or /some-other-page.

You have to encode the value:

$next = rawurlencode('http://example.com/some-other-page?id=10&cat=123');
$url = 'http://example.com/my-page?next='.$next;

All 2 comments

Laravel can't know whether &cat=123 belongs to /my-page or /some-other-page.

You have to encode the value:

$next = rawurlencode('http://example.com/some-other-page?id=10&cat=123');
$url = 'http://example.com/my-page?next='.$next;

See @staudenmeir's answer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iivanov2 picture iivanov2  Â·  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  Â·  3Comments

PhiloNL picture PhiloNL  Â·  3Comments

Anahkiasen picture Anahkiasen  Â·  3Comments

lzp819739483 picture lzp819739483  Â·  3Comments