Welcome Guest, Not a member yet? Register   Sign In
Routing with encoded params
#1

[eluser]xylar[/eluser]
Hi,

I have the following route rule set in my config/routes.php:

Code:
$route["add/url/(:any)"] = "add/url/$1/$2/$3";

This works fine unless the params have encoded values so the following works:

Code:
http://site.com/add/url/true/www.google.co.uk/Google/

but this does not (without spaces):

Code:
http://site.com/add/url/true/http % 3 A % 2 F % 2Fwww.google.co.uk/Google/

It doesn't event seem to get to the controller function the page just says 'Object not found!'. What should I be doing?

Thanks.
#2

[eluser]xylar[/eluser]
It seems it is just the encoded slash (/) that is causing the problems. I tried adding the following to the apache config:

AllowEncodedSlashes On

However this splits up the post param "http://www.google.com" into separate post values: "http:" and "www.google.com".

Maybe I should be doing some decoding or preg_replace in the routes file?
#3

[eluser]InsiteFX[/eluser]
See if this will help you.
[email=http://www.php.net/manual/en/function.rawurlencode.php]PHP.net - rawurlencode[/email]

InsiteFX
#4

[eluser]xylar[/eluser]
I am encoding the url from javascript using encodeURIComponent
#5

[eluser]xylar[/eluser]
To avoid this problem I have decided to base64 the url strings in javascript and decode in the controller. Not the most elegant solution but works for me until I have time to revisit it!
#6

[eluser]freeman[/eluser]
Hi, how about something like

Code:
http://site.com/add?url=http://google.com

I would prefer this one instead of base64'd stuffs on the address bar Smile
#7

[eluser]xylar[/eluser]
i tried using get values before and didn't get much joy, though I didn't try for very long. might give that a go if i go back to it. thanks for the tip Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB