Welcome Guest, Not a member yet? Register   Sign In
if the parameter value has slash, how can i pass it to codeigniter url
#1

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

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

InsiteFX
#3

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

Code:
url_title('Dumb / Dumber');
#4

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

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

InsiteFX
#6

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

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

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

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

[eluser]gcman105[/eluser]
Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB