我需要通过URL传递一些加密值.有没有办法避免加密后我们得到的值中的某些字符,如斜杠(/)?因为在codeigniter中,斜杠等字符用于分隔URL中的参数.请注意,我不希望任何建议不传递URL中的加密字符串:)
class MY_Encrypt extends CI_Encrypt
{
function encode($string, $key="", $url_safe=TRUE)
{
$ret = parent::encode($string, $key);
if ($url_safe)
{
$ret = strtr(
$ret,
array(
'+' => '.',
'=' => '-',
'/' => '~'
)
);
}
return $ret;
}
function decode($string, $key="")
{
$string = strtr(
$string,
array(
'.' => '+',
'-' => '=',
'~' => '/'
)
);
return parent::decode($string, $key);
}
}
Run Code Online (Sandbox Code Playgroud)
--
$key = $this->config->item('encryption_key');
$outboundlink = urlencode( $this->encrypt->encode($segment, $key, TRUE) );
$inboundlink = rawurldecode( $this->encrypt->decode( $segment, $key) );
Run Code Online (Sandbox Code Playgroud)