CodeIgniter Forums
How should data be encoded in the URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: How should data be encoded in the URL (/showthread.php?tid=1151)



How should data be encoded in the URL - guiweber - 02-14-2015

Hi,

I need to put JSON data in my URLs, but when I encode it with urlencode() or rawurlencode() CI complains that "The URI you submitted has disallowed characters."

My current workaround is to first encode using rawurlencode() and then encode the result with base_64encode()... is there a better way to do this?

Code:
base64_encode(rawurlencode($json_data));



RE: How should data be encoded in the URL - CroNiX - 02-16-2015

Why do you "need" to put them in the url?


RE: How should data be encoded in the URL - Narf - 02-16-2015

You can just enable the relevant characters ...

An alternative is this SO answer, which shows how simple it is to make URL-safe Base64 encoding (it's probably not fully compliant with the actual spec, but is completely safe to use regardless): http://stackoverflow.com/a/5835352/468027

Also, you don't need to urlencode if you're going to apply Base64 after that.


RE: How should data be encoded in the URL - guiweber - 02-16-2015

Thanks, I wasn't sure about enabling additional characters because of the intimidating warning in the config file ;- ) I do not fully understand the repercussions it can have on security, so I'll probably stick with the base64 encoding if there is no other way built in CI.


RE: How should data be encoded in the URL - Narf - 02-16-2015

There's a closed (but yet still ongoing) issue on github about the URL-decoding that's currently done by default, so it might end up not requiring you to make an extra effort, but we'll see how that works out ...


RE: How should data be encoded in the URL - Narf - 02-18-2015

Damn forum software ... the following link got double posted for some reason, then both posts disappeared after I deleted only one of them and now doesn't let me post it again until I modify it ... </rant>

https://github.com/bcit-ci/CodeIgniter/commit/0ae4e6c0bd95b7264bee735fb635f317c882bbef


RE: How should data be encoded in the URL - vivekanandhan - 01-06-2017

free online tool for php urlencode function.. kindly take a look on this..
http://onlinew3tools.com/url-encode


RE: How should data be encoded in the URL - Narf - 01-06-2017

(01-06-2017, 02:58 AM)vivekanandhan Wrote: free online tool for php urlencode function.. kindly take a look on this..
http://onlinew3tools.com/url-encode

Did you really have to bump two year-old threads just to advertise this?
It's not like this is a super-hard to do or google thing.