1

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

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.

Problem: When url like this

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

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.

1 Answer 1

6

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 goes to the codeigniter forum, from where I got this.

Sign up to request clarification or add additional context in comments.

5 Comments

Show Fatal Error "CI_Encrypt Not Found"
THNX Nil'z, My issue solve and Guyz NOte ONE thing File name should be MY_Encrypt.php , but load in controller with the same peice of code $this->load->library('encrypt');
I used a custom naming for these functions so that I can still use the core functions. custom_encode() and custom_decode()
then you try to $this->load->library('encrypt'); $this->encrypt->encode($key);
Thanks. This works. For others, make sure you autoload this in your autoload.php file, like this: $autoload['libraries'] = array('encrypt','my_encrypt');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.