CodeIgniter Forums

Full Version: if the parameter value has slash, how can i pass it to codeigniter url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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!

El Forum

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

InsiteFX

El Forum

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

Code:
url_title('Dumb / Dumber');

El Forum

[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);
}

El Forum

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

InsiteFX

El Forum

[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.

El Forum

[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.

El Forum

[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?

El Forum

[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.

El Forum

[eluser]gcman105[/eluser]
Thanks.