在codeigniter中使用加密时忽略斜杠 [英] Ignore Slash while using encryption in codeigniter

查看:256
本文介绍了在codeigniter中使用加密时忽略斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,加密/解密电子邮件,我只是发送一个链接邮件像这样

I have a problem to encrypt/decrypt the email, i just send a link on mail like this

http://www.domain.com/mycontroller/myfunction/McvBsce........etc

最后一个段实际上是一个加密的电子邮件ID,我解密这个电子邮件,并更新stus在我的数据库,当用户点击这个链接。一切正常。

The last Segment is actually a encrypted email id, I decrypt this email and update stus in my db when user click on this link.All done right.

问题:像这样

http://www.domain.com/mycontroller/myfunction/McvB/sce

它显示404错误,因为斜杠包含在生成的加密密钥中。我可以忽略斜杠生成加密,这是我的主要问题,休息都很好。

It shows 404 error, because slash included in the generated encryption key.How can i ignore the slash while it generate the encryption, that's my main problem, rest are working fine.

推荐答案

您需要使用这个类,将这个文件包含在 applicatio / libraries 文件夹,我有同样的问题:

You need to use this class, include this file in your applicatio/libraries folder, I had the same issue:

class MY_Encrypt extends CI_Encrypt
{
    /**
     * Encodes a string.
     * 
     * @param string $string The string to encrypt.
     * @param string $key[optional] The key to encrypt with.
     * @param bool $url_safe[optional] Specifies whether or not the
     *                returned string should be url-safe.
     * @return string
     */
    function encode($string, $key="", $url_safe=TRUE)
    {
        $ret = parent::encode($string, $key);

        if ($url_safe)
        {
            $ret = strtr(
                    $ret,
                    array(
                        '+' => '.',
                        '=' => '-',
                        '/' => '~'
                    )
                );
        }

        return $ret;
    }

    /**
     * Decodes the given string.
     * 
     * @access public
     * @param string $string The encrypted string to decrypt.
     * @param string $key[optional] The key to use for decryption.
     * @return string
     */
    function decode($string, $key="")
    {
        $string = strtr(
                $string,
                array(
                    '.' => '+',
                    '-' => '=',
                    '~' => '/'
                )
        );

        return parent::decode($string, $key);
    }
}

Credit to the codeigniter forum,from where I got这。

Credit goes to the codeigniter forum, from where I got this.

这篇关于在codeigniter中使用加密时忽略斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆