Welcome Guest, Not a member yet? Register   Sign In
Question concerning the encoding of special characters in CodeIgniter URIs, in particular, "/".
#1

[eluser]cmueller[/eluser]
I set up a CodeIgniter system at my localhost.

http://localhost/panta/documents/browse calls the controller "documents" and the method "browse". I am confused as this also works with http://panta.mm.net/documents/browse, although I believe it should rather raise an error.

It seems that CodeIgniter interprets "/" as "/" although the encoding should not imply any such semantics. I am sure that there is a configuration that I might have to change -- does someone know?

Moreover, in the view method of this controller (called via http://localhost/panta/documents/view/{filepath}) a filepath should be passed as one parameter. I used urlencode() to replace "/" with the non-semantic encoding "/". But as these are interpreted as URI segmenters, I get an 404 error. How can I encode a filepath so that it is considered as one parameter although "/" are included? Note that I do not want to segment the filepath as proposed in thread 126224.

Thanks a lot in advance!
#2

[eluser]jedd[/eluser]
Hi cmueller and welcome to the CI forums.

[quote author="cmueller" date="1254680826"]
http://localhost/panta/documents/browse calls the controller "documents" and the method "browse". I am confused as this also works with http://panta.mm.net/documents/browse ...
[/quote]

Perhaps you could explain the relationship between panta.mm.net and localhost. For example, what does the former resolve to?

Quote:It seems that CodeIgniter interprets "/" as "/" although the encoding should not imply any such semantics.

I might be being obtuse here, but I'm not sure I understand the question. Forward slash has a specific function / meaning within a URL.

Are you suggesting that you are trying to get a / into a parameter, for pathing a file, say - and are unable to? You could serialize the path - I'm sure there are some functions in PHP for this - to make it segment-safe, as it were. Alternatively, manage your files via a lookup table, providing an sha1 or md5sum as the visible 'file name' component within the URL.
#3

[eluser]Gwarrior[/eluser]
I'm terribly confused by this. I want to help but it seems you are just telling us that CI is working... and that's it.

Do you want it to NOT work on panta.mm.net?
#4

[eluser]cmueller[/eluser]
Quote:Perhaps you could explain the relationship between panta.mm.net and localhost. For example, what does the former resolve to?

I am sorry, I though I changed this. http://panta.mm.net/ resolves to http://localhost/panta.

Quote:I might be being obtuse here, but I'm not sure I understand the question. Forward slash has a specific function / meaning within a URL.

Are you suggesting that you are trying to get a / into a parameter, for pathing a file, say - and are unable to? You could serialize the path - I'm sure there are some functions in PHP for this - to make it segment-safe, as it were. Alternatively, manage your files via a lookup table, providing an sha1 or md5sum as the visible 'file name' component within the URL.

Please let me rephrase my question. I just realized that "% 2 F" is displayed as "/" in my previous post. I am sorry for the confusion. The correct post is below:

I set up a CodeIgniter system at my localhost. http://localhost/panta/documents/browse calls the controller “documents” and the method “browse”. I am confused as this also works with http://localhost/panta/documents % 2 F browse, although I believe it should rather not.

It seems that CodeIgniter interprets “% 2 F” as “/” although the encoding should not imply any such semantics. I am sure that there is a configuration that I might have to change — does someone know? I changed the apache configuration and added AllowEncodedSlashes ON, but it did not change anything.

Moreover, in the view method of this controller (called via http://localhost/panta/documents/view/{filepath}) a filepath should be passed as one parameter. I used urlencode() to replace “/” with the non-semantic encoding “% 2 F”. But as these are still interpreted as URI segmenters, I get an 404 error. How can I encode a filepath so that it is considered as one parameter although “% 2 F” are included?
Providing an encoding such as with sha1 or md5 would be a solution but does not produce a very nice display for the user ...
#5

[eluser]jedd[/eluser]
Ahh yes, the forum code does try to be a little eager in its helpfulness sometimes.

Have you already discovered [url="http://ellislab.com/forums/viewthread/107486/"]this thread[/url] - as it appears to offer a solution. Fuzzy also dwelt on this problem [url="http://ellislab.com/forums/viewthread/106502/"]in this thread, too[/url] which may contain some useful insight.

I don't know the innards of CI very well, but you may be able to find where it does the translation from % 2f and extend that library, over-riding the method that does the translation. Again, apart from not necessarily being possible, it's also not a hugely elegant approach.

As I mentioned above, my preference is to not try to handle paths anywhere, ever, for this kind of thing - because of these kinds of problems. Especially confusing if/when you shuffle between OS's and file systems. I'd index and track my files in a db table, and my lookups would refer to a (non-pathed) string. They don't need to be md5/sha1/uuid - if the size and ugliness of those concerns you - I just picked them as they tend to be reliably unique and consist of a very small and safe set of characters.
#6

[eluser]cmueller[/eluser]
Thanks a lot for your help!

[quote author="jedd" date="1254754409"]
Have you already discovered [url="http://ellislab.com/forums/viewthread/107486/"]this thread[/url] - as it appears to offer a solution. [/quote]

I have not seen this post but already tried to add a routing. Unfortunately, the routing as give below didn't work for me. I still get an error if either "/" or its encoding are included in the methods-parameter. Then only the first parameter is passed to the view method:

Code:
$route['documents/view/(.+)'] = "documents/view/$1";
$route['documents/view/(:any)'] = "documents/view/$1";

e.g. if document/view/slides/gencs1.omdoc is called then only "slides" is passed as parameter to the view method. Am I missing some configuration for the routing?

[quote author="jedd" date="1254754409"] Fuzzy also dwelt on this problem [url="http://ellislab.com/forums/viewthread/106502/"]in this thread, too[/url] which may contain some useful insight.[/quote]

Thank you for this link. I am not using the proposed library, but the extension has helped me to better understand the internal processes in CodeIgniter.

The initial method in my document controller took one parameter (function view($uri){..}), this was always the first segment of the URL. For example, "slide" for http://localhost/panta/documents/view/sl...ncs1.omdoc

I have changed it as follows:

Code:
function view() {
$uri = $this->uri->uri_string();
$uri = substr($uri,strlen("/documents/view/"),strlen($uri)); ...

The initial value for $uri is "/documents/view/slides/gencs1.omdoc". I remove the first string and use the remaining arguments to retrieve the respective file. This is not a very elegant solution though.

[quote author="jedd" date="1254754409"]
As I mentioned above, my preference is to not try to handle paths anywhere, ever, for this kind of thing - because of these kinds of problems. Especially confusing if/when you shuffle between OS's and file systems. I'd index and track my files in a db table, and my lookups would refer to a (non-pathed) string. They don't need to be md5/sha1/uuid - if the size and ugliness of those concerns you - I just picked them as they tend to be reliably unique and consist of a very small and safe set of characters.[/quote]

Thank you for your proposal. I agree that this would be a good solution and much more maintainable as my approach above. Unfortunately, I need to display the original urls (my users do want to see the full file path).

I have one more question: Should the "% 2 f" encoding be interpreted as segment-separator? I though that the intention of using these encodings is to omit any semantics?

Many thanks for your support!!!
#7

[eluser]jedd[/eluser]
Looks like you've discovered the uri functions - using the rsegment_array might be slightly more elegant, but you're right - it's not the best approach.

My gut feel is using the % 2f stuff should not be interpreted as a slash - that's, as you say, the whole point. But not something I've run into before - as I say, I have other approaches to this problem.

When you say you need to show the full path - do you mean you need to show it somewhere on the page, or specifically in the URL? If you can do it on the page somewhere - a lot of your problems go away.
#8

[eluser]cmueller[/eluser]
[quote author="jedd" date="1254854639"]Looks like you've discovered the uri functions - using the rsegment_array might be slightly more elegant, but you're right - it's not the best approach.[/quote]

You right. I am learning slowly :-).

[quote author="jedd" date="1254854639"]When you say you need to show the full path - do you mean you need to show it somewhere on the page, or specifically in the URL? If you can do it on the page somewhere - a lot of your problems go away.[/quote]

I will consider this, thanks. But after all, it is not so much of a big deal. It's only a research prototype and most likely will not be developed further when I have finished my project. Many thanks for your help!!!




Theme © iAndrew 2016 - Forum software by © MyBB