CodeIgniter Forums

Full Version: URL in query string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Nial[/eluser]
I've tried searching the forums but haven't found anything particularly useful (not saying it's not there, just that I don't know how to phrase my search query). Basically, I want to pass a URL to a method, like so (passing foo.com to the link method):

http://site.com/link/http://foo.com

How do you guys go about this? Something like urlencoding the http://foo.com URL? Will I run into disallowed URI character problems?

El Forum

[eluser]TheFuzzy0ne[/eluser]
Redirects, urlencode() and urldecode().

El Forum

[eluser]Nial[/eluser]
I've created a link controller and have updated config.php to include the following rule:

Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

However, whenever I visit http://site.com/link/http%3 (for example), I get a 404 error. http://site.com/link/http works fine, so it's obviously the % character, but I've made allowances for it. Also, should I receive the invalid URI characters error, instead?

El Forum

[eluser]TheFuzzy0ne[/eluser]
If it was due to the characters being sent in the URI, CodeIgniter would say so, but it's not, so URI characters is not the problem here. That suggests to me that you're controller layout is incorrect. Please can you paste the contents of your controller file, as well as the name and location of the file?

Here's an example controller named "test.php":

Code:
class Test extends Controller { // Extends controller and is named the same as the PHP
                                // file before the dot, but with the first letter capitalised.
    function Test()             // PHP4 compatible constructor name.
    {
        parent::Controller();   // Make sure we call on the parent Controller constructor.
    }

    function index()            // This should be the first function we add. It's the default page.
    {
        // Some stuff here
    }
}

Thanks.

El Forum

[eluser]SitesByJoe[/eluser]
I'd also recommend some string cleanup before sticking a full url in your segments like that.

There's no need to have the "http://" is there?

Code:
str_replace('http://', '', $url);

Same thing with odd characters - unless you really need them. In that case adding a character or 2 to the "allowed" list isn't a big deal. However, the "%" has meaning in a url (for encoding things like commas etc) so using it could be screwing you up.

El Forum

[eluser]SitesByJoe[/eluser]
You could also hash the url so its basic letters and numbers than insert it into your segment.

El Forum

[eluser]pistolPete[/eluser]
[quote author="SitesByJoe" date="1234915906"]You could also hash the url so its basic letters and numbers than insert it into your segment.[/quote]

Derek Allard blogged about that:
http://www.derekallard.com/blog/post/pas...e-igniter/