CodeIgniter Forums
if the parameter value has slash, how can i pass it to codeigniter url - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: if the parameter value has slash, how can i pass it to codeigniter url (/thread-40607.html)



if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 04-13-2011

[eluser]searain[/eluser]
For example, the parameter value is "dump / dummer"

I want to pass this parameter value to the codeigniter site, http://mycisite.com/get/.

http://mycisite.com/get/dump / dummer

Of course, it would not work

urlecode('dump / dummer') and then pass it to http://mycisite.com/get/ still not work.

Thanks!


if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 04-13-2011

[eluser]InsiteFX[/eluser]
Code:
"dump \/ dummer"
Now try urlencode

InsiteFX


if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 04-13-2011

[eluser]micflan[/eluser]
CodeIgniter's URL helper also has a function that would work.

Code:
url_title('Dumb / Dumber');



if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 04-13-2011

[eluser]wh1tel1te[/eluser]
You could base64_encode it, then base64_decode it at the other end:

Code:
echo site_url('controller/method/' . base64_encode($var));

Code:
function method($var)
{
    $var = base64_decode($var);
}



if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 04-13-2011

[eluser]InsiteFX[/eluser]
You could also try adding it here, but not recommended!
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'/;

InsiteFX


if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 04-13-2011

[eluser]searain[/eluser]
thanks i replace / with - before passing the parameter, and replace it back

but url_title seems to be a more universal solution. I will check this out.


if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 04-14-2011

[eluser]searain[/eluser]
base64_encode is the approach i was looking for. Thanks for all your help.

base64_encode has / = which are not valid url characters in CI.

So I could use the str_replace, say replace / with _ replace = with -. and then replace them back and base64_decode it.

Is this the right way to pass the parameter value in url in CI? It has been a trouble for CI that sometimes we need pass values in url and these values have the invalid characters. And I don't want to loose the universal set up for the valid uri characters.

Of course, this way, we get around the uri character validation checking, so we need be extra careful, validation checking these values.


if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 06-28-2011

[eluser]gcman105[/eluser]
I have a similar problem.

I'm writing an application that uses pre existing product data eg: BA/RL

I have setup a controller with a view function that takes the 3rd segment as the product ID, works fine for product ID's without the / in eg: ANT

Whats the best way to hadle this?


if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 06-28-2011

[eluser]searain[/eluser]
"encode" the value before pass
$value = str_replace('=', '-', str_replace('/', '_', base64_encode($value)));

"decode" the value after receive
$value = base64_decode(str_replace('-', '=', str_replace('_', '/', $value)));

You can write a helper like this.

I don't do this on the values input by the end users.

And after receive the value, I validate the value again.


if the parameter value has slash, how can i pass it to codeigniter url - El Forum - 06-29-2011

[eluser]gcman105[/eluser]
Thanks.