CodeIgniter Forums

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

El Forum

[eluser]deadelvis[/eluser]
Hi
I'm trying to write a generic redirect function on my main controller. What is the best way to pass a url in the url?

Generating links with format (url encoded url)...
Code:
<a href"http://mysite.com/redirect/http(%)3A(%)2F(%)2Fothersite.com(%)2Fsomepage.php">


... leads to "Page not found" error, due to the (%)2F in the string being interpreted as /.

Any ideas on how to do this easily?

PS: Percentage sign % substituted by (%) for display reasons

El Forum

[eluser]mglinski[/eluser]
Try base64 encoding.
base64_encode(data)
base54_decode(data)
-Matt

El Forum

[eluser]jwright[/eluser]
I'm having the same issue. I don't really understand XtraFile's response.

But also, I will be generating this type of url from javascript and elsewhere (rather than from with the CodeIgniter app). It would be very convenient to be able to encoded my urls with the standard url encoding...

Can anyone help with fixing the above problem?

El Forum

[eluser]jwright[/eluser]
I was able to solve my problem by url encoding the url twice and then passing it to the controller...

like this ...

http://localhost/myapp/index.php/controller/index/[url encoded twice]

then... CodeIgniter decodes it once automatically (this is why it wasn't working before)... then in your controller your parameter is in url encodeded form (once).

El Forum

[eluser]xwero[/eluser]
Why not use an id instead of the url?

El Forum

[eluser]jwright[/eluser]
In this case I'll be preparing links from outsite the application. I could come up with another more complicated approach involving ids or encrypted urls but this is simpler and much more convenient.

El Forum

[eluser]Nick Husher[/eluser]
You could switch to using query strings instead of CI segments, that might get you a bit farther:

mysite.com/?c=redirect&amp;url=[some url]