Problem with URL and unicode characters
Hi there,
I have a PHP script created in Fusio which gets parameters from the URL and uses those to query a database. There is only an issue with the client which is sending the & and = characters as ASCII code. Is there a way to replace those ASCII codes to the right characters before I use the getParameter funtion?
Here an example of the code: $http_rule = $request->getParameter('value'); $http_code = $request->getParameter('status'); $http_protocol = $request->getParameter('protocol');
The client sends the URL as follows: GET /test/lookup?value=31103%26status%3D402%26protocol%3DGET
Hi, so you could simply use the urldecode function of PHP to decode those values. But is there maybe a problem on the client side since the decoded value looks more correct s. /test/lookup?value=value=31103&status=402&protocol=
The problem is indeed on the client side, but I cannot fixed it there because it is not possible in that piece of software. How can I use the urldecode function for the request url? I tried but it does not work.
You can simply use it like this in your action:
$value = $request->getParameter('value');;
parse_str(urldecode($value), $data);
$http_rule = $data['value'];
$http_code = $data['status'];
$http_protocol = $data['protocol'];
Hmm this does not work I'm afraid.
Ok, so I think the problem regarding the parameters is not related to Fusio but to help you, you may want to take a look at the following script s.
<?php
$value = '31103%26status%3D402%26protocol%3DGET';
parse_str(urldecode($value), $data);
var_dump($data);
This results in:
array(3) {
[31103]=>
string(0) ""
["status"]=>
string(3) "402"
["protocol"]=>
string(3) "GET"
}
so if the $request->getParameter('value'); contains the value like described you could then get those value out of the string. But in general I would of course recommend to fix the request so that you can access the parameters normally via getParameter.
It is weird that above does not work in the PHP Sandbox function.