Welcome Guest, Not a member yet? Register   Sign In
URI changes . to _ (best practice?)
#1

[eluser]escape[/eluser]
Hello,

As posted numerious times in this forum, users encounter situations where CI changes certain characters in a URI to underscores. And in most cases this can be resolved by changing the URI protocol to "REQUEST_URI" or whatever seems to work on your server.

Although I have used this method in the past with success, I'm concerned that changing the URI protocol will introduce unexpected results in other parts of the application.

For example, I have a CI controller which accepts a URI containing decimal numbers. The numbers are passed into a function via the argument list like:

Code:
function crunch_number($decimal)
{
echo $decimal;
}

INPUT: www.mydomain.com/mycontroller/crunch_number/5.369
OUTPUT: 5_369

Where, CI converts the decimal numbers to strings with an underscore

If I do not want to change the URI protocol I simply do this:

Code:
function crunch_number($decimal)
{
echo str_replace('_', '.', $decimal);
}

INPUT: www.mydomain.com/mycontroller/crunch_number/5.369
OUTPUT: 5.369

And life is good.

The point of my post is, can a developer experience unexpected concequences when they change the URI Protocol to fix one thing then discover that change affects something else in the program?

Thanks,
Chris
#2

[eluser]WanWizard[/eluser]
I'm very intrested in the bit of code that would actually perform such a change.
So far, I haven't been able to find it, and I can't find a server to recreate this problem on as well.

I think it is very unlikely that CI would suddenly (sometimes it does, sometimes it doesn't?) decide to modify the URI, and then redirect to it?

I have a feeling there is an external force at work here... Try to find the cause of the problem, instead of nasty kludges to work around it...
#3

[eluser]escape[/eluser]
I too would be interested in finding the root of this, however I suspect the authors of CI, in some form of wisdom, provided the URI Protocols to address a common set of issues found in different operating environments.

In config.php, the definition of URI Protocol is:
Quote:This item determines which server global should be used to retrieve the URI string.

So getting to the root, would seem to be a task of finding what set of server global constitutes a "Delicious Flavor", and go from there.

My CI application is being run on hundreds of servers, and for the most part changing the URI Protocol has proven to work well.

A kludge is precisely what has been put in place :cheese:, simply to improve installation success. Notably an ill-selected URI Protocol (or the default AUTO) also leads to the "white screen of death", AKA the program isn't working.

My preference would be to create an installation controller that would cycle through the Delicious Flavors, and find one that works. If one knew the server global variables, then perhaps a test could be constructed. I'm still noodling on this one :question: .
#4

[eluser]WanWizard[/eluser]
The code to determine which $_SERVER variable to take to fetch thr URI from is not under discussion. That code doesn't alter the URI.

So if you say that you have a case where a dot in the URI mysteriously changes to an underscore, I'm very curious to see a var_dump() of your $_SERVER array, your choosen uri_protocol, and a var_dump() of $this->uri from your controller. Because I would like to know what causes this.

I've never had a situation where AUTO didn't work (I don't work in hosted environments), so I can't comment on improvements of that code. Maybe we should start a new thread where people can post $_SERVER dumps of servers where AUTO doesn't work.
#5

[eluser]escape[/eluser]
I just added this function to the default CI welcome.php controller

Code:
function catch_number($decimal)
    {      
         echo "uri_string: " . $this->uri->uri_string() . '<BR>';
        echo "thrown number: $decimal <BR><BR>";
        foreach($_SERVER as $k => $v) echo "$k => $v<BR>";
    }


Then entered the following in the browser address bar: index.php?/welcome/catch_number/3.14159265

What follows is a summary of the various outputs:

Quote:With the URI PROTOCOL set to:

================== $config['uri_protocol'] = "AUTO"; ==================

CI echos the following:

uri_string: /welcome/catch_number/3_14159265
thrown number: 3_14159265

.many variables in the loop, but QUERY_STRING was of note.
.
QUERY_STRING => /welcome/catch_number/3.14159265
.
.
=======================================================================

With the URI PROTOCOL set to:

================== $config['uri_protocol'] = "QUERY_STRING"; ==================
CI echos the following:

uri_string: /welcome/catch_number/3.14159265
thrown number: 3.14159265

.many variables in the loop, but QUERY_STRING was of note.
.
QUERY_STRING => /welcome/catch_number/3.14159265
.
.
=======================================================================

The other Delicious Flavors do this:

===== $config['uri_protocol'] = "PATH_INFO"; & "ORIG_PATH_INFO" ==================
redirects controller to index()

================== $config['uri_protocol'] = "REQUEST_URI"; ==================
Throws this error message: The URI you submitted has disallowed characters.
#6

[eluser]Unknown[/eluser]
This is a real problem and I faced it on WAMP. I needed file names to be an argument for some of my controller methods, but the extensions always turned from ".jpg" to "_jpg".
solution:
Code:
function view($filename)
{
       $parts = explode("_",$filename);
       $ext   = array_pop($parts);
       $file =  implode("_",$parts).".".$ext;
       echo $file;
}
/*Example
* request url: http://example.com/welcome/view/this_is_a_test.jpg
*
* OUTPUT: this_is_a_test.jpg
*
* location: "./application/controllers/welcome.php"
*
*/

Example:
#7

[eluser]WanWizard[/eluser]
@escape,

Just added that method to the welcome controller of a default CI install (which = AUTO) on my dev machine:

Quote:uri_string: /welcome/catch_number/1.2345
thrown number: 1.2345

SERVER_SIGNATURE => Apache/2.2.17 (Fedora) Server at dev.catwoman.exite.local Port 80
REDIRECT_URL => /ci172/welcome/catch_number/1.2345
REQUEST_URI => /ci172/welcome/catch_number/1.2345
PATH_INFO => /welcome/catch_number/1.2345
PATH_TRANSLATED => /var/www/virtual/dev/welcome/catch_number/1.2345
PHP_SELF => /ci172/index.php/welcome/catch_number/1.2345

i.e. I don't see the conversion anywhere, so it's definately not a generic problem. I've been Googling but I can't find any refererence to this problem. No weird rewrite rules in place that could interfere?

p.s. just tested with CI 2.0-tip as well, but the same results.




Theme © iAndrew 2016 - Forum software by © MyBB