在codeigniter中加密时避免使用特定字符?

Str*_*ger 4 php codeigniter

我需要通过URL传递一些加密值.有没有办法避免加密后我们得到的值中的某些字符,如斜杠(/)?因为在codeigniter中,斜杠等字符用于分隔URL中的参数.请注意,我不希望任何建议不传递URL中的加密字符串:)

Daa*_*aan 6

urlencode加密后使用PHP 函数:http://php.net/manual/en/function.urlencode.phpurldecode在处理GET数据的脚本中使用.


Phi*_*lip 5

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)