Welcome Guest, Not a member yet? Register   Sign In
Escaping characters in a URL
#1

[eluser]tarsusc81[/eluser]
To state the question I'm trying to solve: How can I safely encode/escape non-allowed characters in a URL so they can be passed to a controller?

Typically, to use a non-URI character in a URI, you would use its "percent-encoded" Unicode value, like %26 for ampersand. I was confused when this didn't work for me, because percent-sign is one of the characters explicitly defined as being allowed. After some experimentation, however, I discovered that the Unicode value must actually be interpreted and then compared to the allowed characters, as the aforementioned %26 is rejected as a "disallowed character," while the code for a colon is not.

There must be some way of escaping non-allowed characters in the URL. It's very limiting if there's not.
#2

[eluser]sprise[/eluser]
When using a uri segment to match to a database entry, I add an extra field and call it short_name (or url_title). Into this field goes the basic title of the entry but with only dashes or underscores for punctuation. The effect is domain.com/controller/method/entry-in-question

If for search purposes (only reason coming to mind to need punctuation), you could simply urldecode() the GET value and do the search?

Or did you want the method name to have ampersands?
#3

[eluser]tarsusc81[/eluser]
I don't necessarily have a practical need for it yet. I just stumbled into the question while working with URLs in general. But yes, searching would be a prime example of a case where it's vital to be able to encode any character.

urldecode() isn't needed on anything coming straight from the GET array; it's already decoded. But that's not the point: CodeIgniter automatically unsets the GET array before calling the controller, and on top of that it actually throws an error if any illegal character is in the URL at all. As I said, this applies even if you try to encode an illegal character with "%hexvalue". So you're stuck before you even get anything you could use urldecode() on.

I know config.php has an option where the querystring can be turned back on; I don't know if the restrictions on URL characters would apply to the actual querystring or not. But I've had problems in the past trying to use querystring in combination with CI's normal URL segments; I don't remember the particulars, but I remember it won't work with a FastCGI setup.




Theme © iAndrew 2016 - Forum software by © MyBB