0

While fetching parameters from url(GET Request):

http://localhost:8080/xyz/abc/1234?size=4&chunks=0_5&lang=0,1,2,3

I am able to access argument 1234 and params by:

$params = $request->getQueryParams();
$argument = $args['id'];
$size =  $params['size'];
$chunk = $params['chunks'];

But I am not able to access 'lang' by:

$lang = $params['lang'];

However changing the request parameter from 'lang' to 'langs' seems to work:

 http://localhost:8080/xyz/abc/1234?size=4&chunks=0_5&langs=0,1,2,3

Now I am able to access 'langs' by:

$lang = $params['langs'];

Why is this happening? Is this because lang is a keyword in getQueryParams()? I searched google but did not find a concrete answer. Any help is greatly appreciated.

Thank You for your time.

python_noob
  • 266
  • 3
  • 14
  • You need to use encode your url. Php function is urlencode(). Or you should check this link [https://stackoverflow.com/questions/32668186/slim-3-how-to-get-all-get-put-post-variables] – Suman Sep 24 '18 at 06:40
  • `&lang` is probably being treated as `〈` which is a HTML entity. – Nigel Ren Sep 24 '18 at 06:45
  • What is the output of `$params = $request->getQueryParams(); print_r($params);`? – Nima Sep 24 '18 at 09:03
  • I have tested your code with Slim 3 / PHP 7 and can say that `lang` is working as expected. Do you have any special middleware or firewall? Try `print_r($_GET); exit;` – odan Sep 24 '18 at 09:44
  • 1
    We have application that using `lang` as query string parameter and it is working as expected. May be there is code or middleware that somehow unset it? – Zamrony P. Juhara Sep 26 '18 at 11:32
  • Yes, there was a piece of code which was setting it to a default value. Thanks a lot. – python_noob Sep 26 '18 at 13:23

0 Answers0