Reputation: 27
i want to encrypt our url parameters on one page and decrypt on other page for security reason. when i try this then disallowed character error occurs. also i do not want to set $config['permitted_uri_chars']. according to this.
please give me solution that i can able to encrypt parameters with url like-
wwww.domain.com/controller_name/method_name/parameter1/parameter2
and i am using like for encrypt url-
<a href="<?php echo site_url('C_Name/M_Name/'.$this->encrypt->encode($id)); ?>">Link</a>
and i am using like for decrypt url-
echo $this->encrypt->decode($id)
other issue is that its value is being changed randomly.
Please make me understand that how to do this.
Thanks.
Upvotes: 0
Views: 13968
Reputation: 332
STEP 1: Please create a helper function in helper folder
function encode_url($string, $key="", $url_safe=TRUE)
{
if($key==null || $key=="")
{
$key="tyz_mydefaulturlencryption";
}
$CI =& get_instance();
$ret = $CI->encrypt->encode($string, $key);
if ($url_safe)
{
$ret = strtr(
$ret,
array(
'+' => '.',
'=' => '-',
'/' => '~'
)
);
}
return $ret;
}
function decode_url($string, $key="")
{
if($key==null || $key=="")
{
$key="tyz_mydefaulturlencryption";
}
$CI =& get_instance();
$string = strtr(
$string,
array(
'.' => '+',
'-' => '=',
'~' => '/'
)
);
return $CI->encrypt->decode($string, $key);
}
STEP 2: Assign this file in autoload file
$autoload['helper'] = array('url','form','url_encryption_helper');
STEP 3:
Call function encode_url
in controller, model, view for encryption
$rr="rahul K A";
$a= encode_url($rr);
Upvotes: 5
Reputation: 507
You can use a querystring:
<a href="<?php echo site_url('C_Name/M_Name/?id='.$this->encrypt->encode($id)); ?>">Link</a>
In a query string, you can use anything
Upvotes: 0