Question

I have a url

http://example.com/data/

I want to send json data in that url i.e.

http://example.com/data/{"1":{"id":"some_id","xyz":"1","date":"1397287235418","type":"67878"}}

What is the best way to send json data in the url because when I try to send data in this format it gives error

The URI you submitted has disallowed characters.

I know there is allowed character configuration in CI but if I allow there will be a security issue. I have tried urlencode and in server side used urldecode but it's not helping either Thanks in advance.

Was it helpful?

Solution

In php rawurlencode function escape the invalid character. For example,

<?php 
$str = '{"1":{"id":"some_id","xyz":"1","date":"1397287235418","type":"67878"}}';
$str2 = rawurlencode($str);
?>
<a href="/data/<?php echo $str2; ?>">LINK</a>

This shows the url

http://example.com/data/%7B%221%22%3A%7B%22id%22%3A%22some_id%22%2C%22xyz%22%3A%221%22%2C%22date%22%3A%221397287235418%22%2C%22type%22%3A%2267878%22%7D%7D/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top