CodeIgniter Forums
Passing url as parameter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Passing url as parameter (/showthread.php?tid=3072)



Passing url as parameter - El Forum - 09-07-2007

[eluser]voltechs[/eluser]
Hello all.

Got a problem, which hopefully isn't a tough one.

I want to pass for example "http://www.google.com/" as a parameter to one of my functions in CI, I.E;


http://mysite.here.com/controller/function/url/http://www.google.com/

Now, obviously this wont work, so I tried encoding the url: "http://www.google.com/" => "http:/&#xww;w.google.com/"

This doesn't work either. The browser I believe ultimatly unscrambles it. See, it would be fine if I could use the

http://mysite.here.com/controller/function?url=http:/&#xww;w.google.com/

but we all know that's not how CI works.

Any suggestions? Insights? Solutions?

Cheers,

-- Volte


Passing url as parameter - El Forum - 09-07-2007

[eluser]BravoAlpha[/eluser]
[delete this]


Passing url as parameter - El Forum - 09-07-2007

[eluser]Michael Wales[/eluser]
Count the number of segments, loop through segments 4 through total number of segments, and concatenate. Might have to chop off the last segment (I think the trailing slash will make a new, empty, segment).

I found the best way to do this was to create an array, dumping each segment into that array, and then implode the array with a separator of '/'.


Passing url as parameter - El Forum - 09-08-2007

[eluser]gunter[/eluser]
urlencoding the parameter if its containing a slash does not work...

here is the solution: :coolsmile:
simply get the uri string with $this->uri->uri_string()
and delete the /controller/function/ in this string

Code:
$url_string = $this->uri->uri_string(); // returns /test/albums/www.somethinghere.com
echo str_replace("/test/albums/","",$url_string); // www.somethinghere.com



Passing url as parameter - El Forum - 09-08-2007

[eluser]champs[/eluser]
This is a failing of CI and Kohana, IMO -- at the very least in documentation.

I've been using a solution that safely encodes/decodes URI segments, but builtin functions to do the same, maybe as part of the URI class, would be even nicer. In this situation, you don't have to completely sacrifice URI aesthetics, because the domain name can be added as a segment. I'd say that parse_url() is your friend here.

http://mysite.here.com/controller/function/url/www.google.com/3nc0d3d-s39m3n7-9035-h3r3


Passing url as parameter - El Forum - 09-11-2007

[eluser]obiron2[/eluser]
I had a similar problem...

I was serialising an object to pass as a CI URI segment (the data is an order with n lines and I need to pass all the order data back in one go - don't ask me why) I found the solution was to encode it twice in javascript client side. This way if there were any illegal characters I knew they had been properly encoded when the browser/CI tried to unencode them.

This obviously makes the URI larger and there is a small overhead in unencoding CI side.

Obiron


Passing url as parameter - El Forum - 09-11-2007

[eluser]ELRafael[/eluser]
Do you really need the "/" in the url? Try to pass just the google.com and then put de correct /